MongoDB Reference

This section documents the current MongoDB 8.x server line as published at the MongoDB Server Manual, which is the reference these pages are written and verified against. No specific patch version is pinned. Some capabilities (Atlas Search, Atlas Vector Search, and parts of encryption and backup) are Atlas-only — they are linked, not documented in depth.

This content was generated with the assistance of AI and should be verified against the official manual before being relied on in production, since MongoDB iterates quickly.

This section’s bibliography lists the reference material consulted while preparing these pages.

Welcome to the MongoDB reference. MongoDB is a general-purpose, document-oriented database: it stores records as JSON-like BSON documents rather than as rows in fixed tables, gives each collection a flexible schema, exposes a rich Query API and an aggregation pipeline instead of SQL, and scales horizontally by sharding a collection across many servers. This section documents the current MongoDB server line as a database-developer reference — the data model, the CRUD and aggregation surface, indexing, schema design, transactions and change streams, replication and sharding, storage, security and operations, and the drivers — written and verified against the MongoDB Server Manual.

If you are new to MongoDB, read Getting Started first, then Documents, BSON & Data Types and Databases, Collections & Schema Control, followed by the three CRUD pages — Inserting Data, Bulk Writes & Write Concern, Reading Data with the Query API, and Updating & Deleting Documents. Everything after that builds on those foundations.

For the relational baseline this section contrasts with, see the sibling SQL Reference, which the MongoDB pages cross-link rather than restate.

What’s covered

Getting started

  • Getting Started — MongoDB as a general-purpose document database, the document model versus the relational model, the Community, Enterprise and Atlas editions, running a local mongod, connecting with mongosh, and mongosh as a full JavaScript REPL.

Data & schema

  • Documents, BSON & Data Types — the document, the BSON binary format and its 16 MB / nesting limits, the full BSON type set and Extended JSON, _id and ObjectId, embedded documents and arrays with dot notation, and BSON comparison and sort order.

  • Databases, Collections & Schema Control — implicit creation on first write, naming rules, $jsonSchema validation with validationLevel / validationAction, capped, TTL, clustered and time series collections, and views and on-demand materialized views.

CRUD / Query API

  • Inserting Data, Bulk Writes & Write Concern — insertOne / insertMany, ordered versus unordered bulkWrite, the write-result shape, { w, j, wtimeout } write concern, and retryable writes.

  • Reading Data with the Query API — find / findOne, the query filter document, projection, the comparison / logical / element / evaluation operators, embedded-document and array matching, cursor methods, and avoiding large `skip()`s with a range-query alternative.

  • Updating & Deleting Documents — updateOne / updateMany / replaceOne, the field and array update operators, the positional operators with arrayFilters, upserts, findOneAndUpdate, pipeline-form updates, and deleteOne / deleteMany.

  • Indexing & Query Performance — creating and listing indexes, single-field, compound (the Equality, Sort, Range rule) and multikey indexes, covered queries, reading explain() and the plan cache, the index properties (unique, partialFilterExpression, sparse, TTL, hidden, collation), rolling builds, hint, and when not to index.

  • Text, Wildcard, Geospatial & Atlas Search — text indexes with $text and $meta: "textScore", wildcard indexes, 2dsphere and legacy 2d geospatial indexes, hashed indexes, and an overview of Atlas Search and Atlas Vector Search.

Aggregation

  • The Aggregation Framework — the pipeline model, the core stages, aggregation expressions and system variables, $expr inside find, pipeline optimization and explain, and why standalone map-reduce is superseded.

Schema design

  • Schema Design for the Document Model — embed versus reference, relationship cardinality, the normalization trade-off, the standard schema design patterns and anti-patterns, schema versioning and migration, and when a document database is the wrong fit.

Transactions & change streams

  • Multi-document ACID Transactions — single-document atomicity versus a transaction, client sessions, session.withTransaction versus explicit start / commit / abort, read and write concern inside a transaction, and the limits that keep transactions short.

  • Reacting to Data Changes — watch() on a collection, database or deployment, the change-event document shape, resume tokens, filtering with an aggregation pipeline, and fullDocument: "updateLookup".

Replication & sharding

  • Replica Sets & High Availability — the primary / secondary topology, the oplog and initial sync, elections and heartbeats, read preference, write concern, read concern, causal consistency, and the rs.* configuration commands.

  • Horizontal Scaling with Sharded Clusters — shards, mongos routers and the config-server replica set, ranged / hashed / compound shard keys, choosing a shard key, and the balancer, zones and resharding.

Storage, security & operations

  • WiredTiger, Journaling & Durability — document-level concurrency and MVCC, the cache, checkpoints and compression, the write-ahead journal, and how write concern and read concern extend durability to a replica set.

  • Authentication, Authorization & Encryption — enabling access control and the localhost exception, the authentication mechanisms, role-based access control, TLS for client and intra-cluster traffic, encryption at rest and field-level encryption, and the security checklist.

  • Running & Observing a Deployment — starting and stopping mongod from the command line or a YAML config file, db.currentOp() / db.killOp() and the database profiler, and monitoring with serverStatus, mongostat, mongotop and the production-notes tuning.

  • Backups, Import/Export & GridFS — mongodump / mongorestore, filesystem and volume snapshots, Atlas / Ops Manager continuous backup, mongoexport / mongoimport and bsondump, and storing large files with GridFS.

Drivers & tooling

  • Connecting from an Application & the Tooling — the official drivers and their shared CRUD / aggregation surface, the connection-string URI and its options, connection pooling and the singleton client, the Stable API, and the mongosh / Compass / Database Tools / Atlas CLI tooling.

Cheat sheet

  • Cheat Sheet (PDF) — a single-page, printable summary of everything in this section, with a downloadable PDF.

Bibliography