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 withmongosh, andmongoshas 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,
_idandObjectId, embedded documents and arrays with dot notation, and BSON comparison and sort order. -
Databases, Collections & Schema Control — implicit creation on first write, naming rules,
$jsonSchemavalidation withvalidationLevel/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 unorderedbulkWrite, 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 witharrayFilters, upserts,findOneAndUpdate, pipeline-form updates, anddeleteOne/deleteMany.
Indexing & search
-
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
$textand$meta: "textScore", wildcard indexes,2dsphereand legacy2dgeospatial 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,
$exprinsidefind, pipeline optimization andexplain, 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.withTransactionversus 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, andfullDocument: "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,
mongosrouters 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
mongodfrom the command line or a YAML config file,db.currentOp()/db.killOp()and the database profiler, and monitoring withserverStatus,mongostat,mongotopand the production-notes tuning. -
Backups, Import/Export & GridFS —
mongodump/mongorestore, filesystem and volume snapshots, Atlas / Ops Manager continuous backup,mongoexport/mongoimportandbsondump, 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
-
MongoDB Server Manual — the source every page in this section is written and verified against; see in particular Introduction, CRUD Operations, Query and Projection Operators, Update Operators, Indexes, the Aggregation Pipeline with its stage and operator references, Data Modeling, Transactions, Change Streams, Replication, Sharding, WiredTiger, and Security.
-
docs.mongodb.com more broadly —
mongosh, the drivers, the connection-string reference, Compass, the Database Tools, Atlas (including Atlas Search and Atlas Vector Search), and the release notes. -
MongoDB University — free courses and learning paths on the topics above.
-
Bradshaw, Shannon; Brazil, Eoin; Chodorow, Kristina. MongoDB: The Definitive Guide — Powerful and Scalable Data Storage, 3rd ed. O’Reilly Media, 2019. ISBN 978-1-491-95446-1. Consulted as part of the bibliography for this section (targets roughly MongoDB 4.0 / 4.2) — see the publisher’s book page, oreilly.com, and the companion code repository at mongodb-the-definitive-guide-3e.