MongoDB Expert Knowledge

MongoDB Expert

This local skill is generated from docs/mongodb-expert-context.md in 10gen/mdb-tam.

This skill consolidates 24 MongoDB data-plane/engine sub-skills as on-demand reference files under references/. It is the primary, first-choice skill for core MongoDB questions — not a fallback. Match the task to the Sub-skill routing table below and Read the listed references/…md file before answering deep questions — the table alone is not enough for depth. Route to a sibling hub (mongodb-atlas-expert, atlas-diagnostics-expert, mongodb-operations-expert, mongodb-kb) only when the question falls into one of those domains (see frontmatter SKIP).

When to use this skill

Use this skill when the user needs help with core MongoDB data-plane or database-engine topics. Start from the bundled context below for fundamentals, load the relevant references/ file for depth, and defer to the cited official documentation for exact APIs, commands, and edge-case behavior.

Sub-skill routing table

This hub absorbs 24 former standalone skills as on-demand reference files. When a task matches a row, Read the listed references/ file before answering — do not rely on this table alone for depth. For domains not listed here (Atlas cloud platform, live diagnostics, ops/backup/migration/security, KB lookup), route to the sibling hub named in the frontmatter SKIP line.

Sub-topic When to load Reference file
mongodb-developer Driver usage across all official drivers (Node.js, Python, Java, Go, C#, Rust, …) — connection pooling, transactions, bulk ops, GridFS references/mongodb-developer.md
mongodb-aggregation-pipeline Aggregation pipeline fundamentals — stage order, operators, materialization references/mongodb-aggregation-pipeline.md
mongodb-aggregation-stages-deep Deep aggregation stages — $lookup, $graphLookup, $facet, $bucket/$bucketAuto, $merge/$out, $setWindowFields, $densify/$fill, $unionWith references/mongodb-aggregation-stages-deep.md
mongodb-indexes-deep Every index type — single-field, compound, multikey, partial, wildcard, hidden, TTL, hashed references/mongodb-indexes-deep.md
mongodb-query-performance Query optimization, explain plans, ESR rule, slow-query diagnosis, index hints references/mongodb-query-performance.md
mongodb-schema-design Embedding vs referencing trade-offs, 12 canonical design patterns, tree structures, validation references/mongodb-schema-design.md
mongodb-transactions Multi-document transactions — replica-set and sharded, callback API, retry, read/write concerns references/mongodb-transactions.md
mongodb-change-streams Change streams — oplog architecture, resume tokens, pre/post images, split events references/mongodb-change-streams.md
mongodb-time-series Time-series collections — timeField/metaField, granularity, bucketing, TTL, downsampling references/mongodb-time-series.md
mongodb-geospatial Geospatial queries, indexes, and data model — 2dsphere, GeoJSON, near/within, polygons references/mongodb-geospatial.md
mongodb-views-materialized-views Standard read-only views and on-demand $merge-backed materialized views references/mongodb-views-materialized-views.md
mongodb-bson-types BSON type system — type table with codes/aliases, comparison order, edge cases references/mongodb-bson-types.md
mongodb-error-codes Numeric server error codes and correct driver retry behavior references/mongodb-error-codes.md
mongodb-connection-string Connection-string URI formats and options — SRV, TLS, authSource, appName references/mongodb-connection-string.md
mongodb-driver-internals Driver internals — CMAP connection pooling, SDAM, server selection, retryable writes, OCSP references/mongodb-driver-internals.md
mongodb-drivers-k8s Driver patterns plus Kubernetes operator — connection management, transactions, change streams, retry references/mongodb-drivers-k8s.md
mongodb-wiredtiger WiredTiger internals, cache tuning, eviction mechanics, checkpoint behavior references/mongodb-wiredtiger.md
mongodb-wiredtiger-internals WiredTiger deep internals — cache, checkpointing, MVCC, eviction, snapshot reads references/mongodb-wiredtiger-internals.md
mongodb-mongosh mongosh shell — methods, scripts, snippets, db.* admin commands references/mongodb-mongosh.md
mongodb-database-tools Database tools — mongodump, mongorestore, mongoimport, mongoexport, archive/BSON streaming references/mongodb-database-tools.md
mongodb-multi-tenancy Multi-tenancy data layout — tenant-per-DB, tenant-per-collection, shared collection references/mongodb-multi-tenancy.md
mongodb-sharding Sharding architecture, shard-key selection (ranged, hashed, compound), balancer, zones, resharding references/mongodb-sharding.md
mongodb-replication Replica-set architecture — primaries/secondaries/arbiters/hidden/delayed, elections, oplog, failover references/mongodb-replication.md
mongodb-compass Compass GUI — query builder, schema analysis, performance tab references/mongodb-compass.md

Cross-hub routing (domains this hub does NOT own)

The Sub-skill routing table above is the authoritative map of the 24 reference files this hub owns — always route data-plane/engine depth through references/<name>.md, never to a standalone skill name (those skills no longer exist).

For domains outside this hub, route to the sibling hub that owns them. Each sibling hub has its own internal routing table for its sub-areas — do not name individual sub-skills here:

Domain area Route to sibling hub
Atlas cloud platform / control plane — orgs, projects, deployments, Admin API, Atlas CLI, Terraform, Kubernetes Operator (AKO), tiers, IAM/RBAC, federated auth, service accounts, Atlas Search / $search, Vector Search / $vectorSearch, Search Nodes, Stream Processing, Charts, Data Federation, Online Archive, App Services, Triggers/Functions, Device SDK / Realm sync, BI Connector, analytics nodes, global clusters, Flex/Serverless, multicloud + AWS/Azure/GCP networking mongodb-atlas-expert
Live cluster diagnostics, performance troubleshooting, benchmarking, monitoring/observability, capacity planning atlas-diagnostics-expert
Backup/restore, disaster recovery, Ops Manager, migration (mongosync, Relational Migrator, Live Migration, cutover), upgrade paths, security architecture, encryption (CSFLE/Queryable Encryption), compliance, cost optimization, Kafka/Spark connectors, CDC architecture mongodb-operations-expert
KB / troubleshooting article lookup mongodb-kb
Install / run MongoDB locally from a repo 10gen
Generic schema/data-migration patterns (expand-contract, backfill, zero-downtime) database-migrations

When a question crosses categories, pick the deepest reference that covers the primary concern, load it, then cross-link to the relevant sibling hub for the secondary concern.

Skill guidance

Bundled context

Source: docs/mongodb-expert-context.md in the mdb-tam repository.


MongoDB expert context

How to use this context

Use this file as a practical MongoDB reference when designing schemas, writing queries, reviewing data-access code, or debugging performance issues. Treat the MongoDB Manual and driver docs as the primary operational/application references, and use the MQL, operator, command, and method reference pages for exact behavior and syntax details (MongoDB Manual, MongoDB Drivers, MQL reference, mongosh methods).

Source scope

Quick rules

  1. Model data around access patterns; data accessed together should generally be stored together (Data modeling).
  2. Prefer embedding when it lets you satisfy common reads in a single-document fetch; MongoDB explicitly highlights document structures as a way to avoid unnecessary multi-document transactions (Data modeling, Transactions).
  3. Remember that write operations are atomic at the single-document level, but multi-document operations are not atomic as a whole unless you use transactions (CRUD, Write atomicity, Transactions).
  4. Create indexes for repeatedly queried fields, but remember every index has a write cost (Indexes).
  5. Prefer aggregation pipelines for aggregations; MongoDB calls them the preferred aggregation method (Aggregation).
  6. Use the driver in applications; the MongoDB docs explicitly note that most interactions use an idiomatic driver rather than JavaScript shell methods (mongosh methods, MongoDB Drivers).
  7. When concurrent updates matter, include the expected current value in the filter or use operators like $inc to avoid accidental lost updates (Write atomicity).
  8. Use transactions only when you truly need multi-document atomicity; many use cases can be modeled to avoid them (Transactions, Data modeling).
  9. Treat MQL as more than simple find filters: it includes query predicates, projections, updates, expressions, and aggregation stages/operators (MQL reference).
  10. Separate driver usage from mongosh usage in your mental model; shell methods are reference and tooling conveniences, not the main application API surface (mongosh methods, MongoDB Drivers).

Core MongoDB model

Document model and collections

MQL and how to think about it

CRUD and write semantics

CRUD basics

Atomicity and concurrent updates

Transactions

Data modeling and schema design guidance

Core design principle

Embedding vs referencing

Indexes and performance

Aggregation

Driver vs mongosh guidance

Methods, operators, and APIs inventory

This is a condensed high-value inventory, not a verbatim dump of every MongoDB operator or method.

CRUD methods and commands

API Purpose Key args/params Return/effect Typical usage Caveats
db.collection.insertOne() Insert one document (CRUD) document Adds one document to a collection Single-document creation Targets one collection; creates collection if needed
db.collection.insertMany() Insert multiple documents (CRUD) array of documents Adds many documents Batch creation Still collection-scoped
find command / db.collection.find() Select documents from a collection or view (CRUD commands) query filter, projection, options Returns matching documents/cursor semantics depending API Reads by predicate Behavior differs slightly by driver/shell surface
update command / update methods Update one or more documents (CRUD commands) filter, update document/operators, options Modifies matched docs Targeted updates Single-doc atomicity only
delete command / delete methods Delete one or more documents (CRUD commands) filter Removes matched docs Cleanup or lifecycle deletion Multi-doc deletions are not atomic as a whole
findAndModify Modify and return a single document (CRUD commands) filter, modification, options Returns/modifies one document Read-modify-write workflows Single-document oriented
aggregate Run aggregation pipeline on collection or view (CRUD commands, Aggregation) pipeline stages, options Computed result set Analytics, reshaping, derived results Prefer pipelines over older/simpler aggregation approaches
distinct Return distinct values for a field (CRUD commands) field, filter/options Unique values Faceting-style retrieval Index support matters for performance
bulkWrite Perform many write ops in one request (CRUD commands) batched operations Many inserts/updates/deletes High-throughput batch write workflows Command-level semantics are version-sensitive; docs note it is new in 8.0

Query, projection, and update operators

API Purpose Key args/params Return/effect Typical usage Caveats
Query predicates Boolean document matching expressions (Query operators) field/operator/value expressions Match or reject documents Filtering in reads and updates Operator category matters: array, comparison, logical, geospatial, etc.
$eq and other comparison operators Compare field values in predicates (Query operators) field comparisons Match docs by comparison Standard filtered reads Use the right operator family for the predicate
$expr Use expressions inside query predicates (Aggregation operators) expression tree Boolean match behavior in query context Computed predicate logic Pulls expression semantics into query matching
$ projection operator Project first array element matching query condition (Projection operators) projection syntax Limits returned array content Array-focused reads Not supported on view find() operations
$elemMatch projection Project first array element matching explicit condition (Projection operators) $elemMatch projection condition Limits returned array content Focused array projections Not supported on view find() operations
$slice projection Limit number of projected array elements (Projection operators) skip/limit slice args Returns subset of array Smaller array payloads Not supported on view find() operations
$set Set field value in document (Update operators) field/value map Overwrites target field values Standard updates Can clobber concurrent overwrite-based updates
$inc Increment numeric field by amount (Update operators, Write atomicity) field/amount map Adds delta Counters, safer concurrent increments Preferred in some concurrent update scenarios
$currentDate Set field to current date or timestamp (Update operators) field spec Writes current temporal value Updated-at style fields Field ordering behavior is version-sensitive
$setOnInsert Set field only on upsert-insert path (Update operators) field/value map Applies only when upsert inserts Default values on upsert No effect on plain matched update

Aggregation building blocks

API Purpose Key args/params Return/effect Typical usage Caveats
Aggregation pipeline Preferred aggregation flow (Aggregation) ordered list of stages Transforms/aggregates documents Reporting, reshaping, analytics Stage order matters
$project Reshape/project fields (Aggregation operators) projection expression New document shape Output shaping Expression-driven, stateless logic
$addFields Add computed fields (Aggregation operators) field/expression mapping Augmented document Derived values mid-pipeline Watch pipeline complexity
$group Group documents and compute accumulated values (Aggregation, Aggregation operators) grouping key plus accumulators Grouped aggregate output Rollups and metrics Requires accumulator semantics
Expressions such as $add Compute values from constants, operators, and field paths (Aggregation operators) operator plus operands Value result Arithmetic, transforms, computed projections Expressions are stateless

Coding standards and best practices from the docs

Schema and data modeling

Collection design

Embedding vs referencing

Query design

Index strategy

Aggregation usage

Update patterns

Transaction usage

Driver usage vs shell usage

Maintainability and performance

Practical defaults for future coding tasks

Known ambiguities / version-sensitive notes

Cross-hub map — where every MongoDB topic lives

All MongoDB knowledge is split across four hubs (plus mongodb-kb for KB-article lookups and 10gen for repo install/run). If a task’s deep material is not in this hub’s Sub-skill routing table, it is a reference file under a sibling hub — activate that hub or Read its references/<name>.md directly.

Hub Owns Example reference files
mongodb-expert Core data plane + engine internals: CRUD/MQL, aggregation, indexes, query performance, schema design, transactions, change streams, time-series, geospatial, views, BSON, error codes, connection strings, driver internals, WiredTiger cache/eviction/checkpoint internals, mongosh, database tools, multi-tenancy, sharding, replication, Compass references/mongodb-wiredtiger-internals.md, mongodb-indexes-deep.md, mongodb-sharding.md, mongodb-replication.md
mongodb-atlas-expert Atlas cloud platform: control plane, Atlas Search, Vector Search, Stream Processing, Charts, Data Federation, App Services, Triggers, Online Archive, Flex, networking, IAM/RBAC, Terraform, AKO references/mongodb-atlas-search.md, mongodb-atlas-vector-search.md
atlas-diagnostics-expert Live diagnostics & performance: ts-diag, FTDC, performance-troubleshooting symptom triage, benchmarking, monitoring/observability, capacity planning references/mongodb-performance-troubleshooting.md
mongodb-operations-expert Ops & data movement: backup/restore, DR, Ops Manager, upgrades, migration, mongosync, relational migrator, CDC, data lifecycle, security architecture, encryption, compliance, cost, Kafka/Spark connectors references/mongosync.md, mongodb-backup-restore.md

High-overlap routing notes: