mongodb
/mongodb
Expert MongoDB document database assistance covering aggregation pipelines, compound indexes, replica sets, and sharding. Use when designing flexible JSON schemas, querying geospatial data, or scaling document stores.
- Author
- G1Joshi ↗
- Repository
- Agent-Skills ↗
- Licence
- MIT
- Last repository change
- 01.10.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 2
No signals detected. Repository changed on 01.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Expert MongoDB document database assistance covering aggregation pipelines, compound indexes, replica sets, and sharding. Use when designing flexible JSON schemas, querying geospatial data, or scaling document stores.
Original author description
Expert MongoDB document database assistance covering aggregation pipelines, compound indexes, replica sets, and sharding. Use when designing flexible JSON schemas, querying geospatial data, or scaling document stores.
How it works
- When to Use
- Quick Start
- Core Concepts
- Common Patterns
- Best Practices
- Troubleshooting
- References
SKILL.md preview
---
name: mongodb
description: Expert MongoDB document database assistance covering aggregation pipelines, compound indexes, replica sets, and sharding. Use when designing flexible JSON schemas, querying geospatial data, or scaling document stores.
---
# MongoDB
MongoDB is a document database. It stores data in JSON-like documents (BSON). It is the most popular NoSQL database, known for flexibility and scalability.
## When to Use
- **Flexible JSON Document Storage**: Modeling evolving, nested domain entities with polymorphic schemas in BSON.
- **High-Velocity Operational Data Stores**: Content management, e-commerce product catalogs, and user personalization platforms.
- **Rich Aggregation Pipelines**: Transforming, joining ($lookup), grouping, and projecting analytical data streams in real time.
- **Global Sharding & Geospatial Indexing**: Scaling collections horizontally across shards and executing 2dsphere geo queries.
## Quick Start
```javascript
// Using Mongoose (Node.js)
const kittySchema = new mongoose.Schema({
name: String,
});
const Kitten = mongoose.model("Kitten", kittySchema);
const silence = new Kitten({ name: "Silence" });
await silence.save();
```
## Core Concepts
### BSON Documents & Schema Flexibility
Data is stored as binary JSON (BSON), supporting native dates, 64-bit integers, decimals, and geospatial points:
```javascript
// MongoDB Document in collections/orders
{
"_id": ObjectId("66f6ab42d1e1c3a628a58a98"),
"orderNumber": "ORD-2026-901",
"customer": { "id": "cust_12", "email": "alex@example.com" },
"items": [
{ "sku": "WIDGET-01", "qty": 2, "price": 49.99 }
],
"shippingAddress": {
"type": "Point",
"coordinates": [-73.9851, 40.7488] // 2dsphere GeoJSON
},
"status": "PROCESSING",
"createdAt": ISODate("2026-09-27T10:00:00Z")
}
```
### Powerful Multi-Stage Aggregation Framework
Transforms and aggregates documents through sequential pipeline stages:
```javascript
db.orders.aggregate([
{
$match: { status: "COMPLETED", createdAt: { $gte: ISODate("2026-01-01") } },
},
{ $unwind: "$items" },
{
$group: {
_id: "$items.sku",
totalRevenue: { $sum: { $multiply: ["$items.qty", "$items.price"] } },
unitsSold: { $sum: "$items.qty" },
},
},
{ $sort: { totalRevenue: -1 } },
{ $limit: 5 },
]);
```
### Replica Sets & Automated Failover
Ensures high availability through 3-node primary-secondary elections:
```text
[ Primary (Read/Write) ] ──Oplog Replication (Async)──→ [ Secondary (Read Replicas) ]
│
▼
[ Secondary (Voter) ]
```
## Common Patterns
### Aggregation Pipeline with Lookup and Facets
**Problem**: Normalizing and joining related documents across collections efficiently in a single query.
**Solution**:
Use `$lookup` with `$project` and pagination `$facet`:
```javascript
db.orders.aggregate([
{
$match: { status: "DELIVERED", createdAt: { $gte: ISODate("2025-01-01") } },
},
{
$lookup: {
from: "users",
localField: "userId",
foreignField: "_id",
as: "customer",
},
},
{ $unwind: "$customer" },
{
$project: {
orderId: "$_id",
totalAmount: 1,
customerName: "$customer.name",
customerEmail: "$customer.email",
},
},
{ $sort: { totalAmount: -1 } },
{ $limit: 20 },
]);
```
## Best Practices
**Do**:
- Design for Data Access Patterns: Embed data that is read together frequently; reference data when unbounded growth is expected.
- Follow the ESR Rule for Indexes: Order compound indexes by **Equality** first, **Sort** second, and **Range** last.
- Enable JSON Schema Validation: Enforce required fields and types at the collection level via `$jsonSchema`.
- Use Bulk Operations: Batch multiple write operations using `bulkWrite()` to minimize network roundtrips.
**Don't**:
- Create unbounded arrays inside documents: Unbounded arrays degrade performance and can hit the 16MB document size limit.
- Use `$lookup` excessively: MongoDB is not a relational database; heavy multi-collection joins destroy throughput.
- Perform unindexed queries: Run `.explain("executionStats")` to verify queries utilize `IXSCAN` rather than `COLLSCAN`.
## Troubleshooting
| Error | Cause | Solution |
| :--------------------------------------------------------------- | :--------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------- |
| `Executor error during find command: OperationExceededTimeLimit` | Query performing full collection scan (`COLLSCAN`) without supporting index. | Run `explain('executionStats')` and add compound index matching filter and sort keys. |
| `WriteConflict error` | Concurrent updates modifying same document concurrently in WiredTiger. | Implement retry logic in application layer or batch modifications. |
| `BSONObj size exceeds maximum allowed size (16MB)` | Single document exceeded 16MB limit due to unbounded arrays. | Refactor schema: move unbounded child arrays into separate collection with parent references. |
## References
- [MongoDB Manual](https://www.mongodb.com/docs/manual/)
- [MongoDB University](https://learn.mongodb.com/)
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · G1Joshi/Agent-Skills | 100 | MIT |
| ericrisco/rsc-harness | 100 | MIT |
| FrancoStino/opencode-skills-collection | 100 | MIT |
| TerminalSkills/skills | 100 | Apache-2.0 |
| sickn33/agentic-awesome-skills | 100 | MIT |
| claude-dev-suite/claude-dev-suite | 100 | MIT |
| lynricsy/hyperskills | 100 | MIT |
| PIXARTSeu/Synapse | 100 | AGPL-3.0 |
| MARUCIE/openclaw-foundry | 100 | MIT |
Database snapshot: 13.11.2026 · package version 586f8ac11eea (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100mongodb-expert
Designs MongoDB schemas, indexes, and aggregation pipelines that perform - embed-vs-reference decision rules, the 16MB document limit, ESR compound-index ordering, explain-plan verification, and operational settings for replica sets and sharding. Use when someone asks "should I… - 100mongodb-indexing-replica-sets
Use this skill when configuring MongoDB replica set elections, write concerns, compound indexes, and sharded clusters. - 100mongodb-expert
Expert-level MongoDB database design, aggregation pipelines, indexing, replication, and production operations. Use when the user mentions NoSQL, database, aggregation, or performance, or when the task involves CRUD Operations, Query Operators, Aggregation Pipeline, or Indexing. - 100mongodb-schema-and-indexing
Production-grade MongoDB schema design patterns, indexing strategies, ESR rule (Equality, Sort, Range), aggregation framework optimization, and sharding/partitioning architectures. Use when designing MongoDB schemas, tuning query performance, or building aggregation pipelines. - 95mongodb-natural-language-querying
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents. Use this skill whenever the user asks to write, create, or generate MongoDB queries, wants to filter/query/aggregate data in MongoDB,… - 100mongodb-document-modeling-aggregation
Use this skill when modeling polymorphic document collections and executing multi-stage aggregation pipelines in MongoDB.