MongoDB is an open-source, document-oriented NoSQL database that stores data in flexible, JSON-like BSON documents. Known for horizontal scalability, rich querying, and a powerful aggregation framework, MongoDB is used by organizations ranging from startups to Fortune 500 companies. The current stable release is the MongoDB 8.3 series, continuing the 8.x line that opened with 8.0 (GA October 2024) and brought a bulkWrite command spanning multiple collections, updateOne with sort, Queryable Encryption range queries, automatic compaction, per-CPU TCMalloc caches, and significant performance improvements. MongoDB Atlas, the fully managed cloud service, continues to expand with Atlas Vector Search, Atlas Stream Processing, and Atlas Search. This cheat sheet covers the complete MongoDB ecosystem from basic CRUD operations and query operators through advanced aggregation, indexing strategies, replication, sharding, security, and Atlas-specific features.
What This Cheat Sheet Covers
This topic spans 51 focused tables and 419 indexed concepts, 185 flashcards, 17 practice tests with 547 questions. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: BSON Data Types
MongoDB stores every document as BSON, a binary format carrying real types that JSON never had, such as Date, ObjectId, Binary and Decimal128. Choosing the right one matters more than it looks: Decimal128 keeps money exact where Double quietly rounds it, Timestamp is internal replication plumbing rather than a way to store dates, and _id accepts far more than just an ObjectId. These are the primitives every document is built from.
| BSON Type | Example | Description | |
|---|---|---|---|
{ rating: 4.5 } | β’ 64-bit binary floating point (IEEE 754) β’ approximates decimal fractions, so avoid it for money | ||
{ name: "MongoDB" } | UTF-8 encoded character string | ||
{ addr: { city: "NYC" } } | β’ Embedded/nested BSON document β’ fields are ordered, so whole-document equality is order-sensitive | ||
{ tags: ["db", "nosql"] } | β’ Ordered list of values of any BSON type β’ an ascending sort compares each array's smallest element | ||
BinData(0, "data") | β’ Byte array plus a subtype that says how to interpret it β’ used for files, encrypted fields, UUIDs | ||
ObjectId("507f1f77bcf86cd799439011") | β’ 12 bytes: 4-byte creation timestamp, 5-byte random, 3-byte counter β’ the _id a driver generates when you omit oneβ’ roughly, not strictly, ordered by creation time | ||
{ active: true } | β’ true or false valueβ’ a distinct type from the number 1, matched by $type: "bool" | ||
{ created: ISODate("2026-04-21") } | β’ Signed 64-bit integer, milliseconds since the Unix epoch β’ build it with new Date() or ISODate(), since bare Date() returns a string | ||
{ middle: null } | β’ An explicit null value, not the same thing as an absent field β’ sorts below every number | ||
{ pattern: /^mongo/i } | β’ Perl-compatible pattern, PCRE2 since MongoDB 6.1 β’ storable as a field value, not only usable in a query | ||
{ count: Int32(42) } | β’ 32-bit signed integer β’ Int32() in mongosh, legacy alias NumberInt()β’ what a bare whole number becomes in mongosh | ||
Timestamp(1714700000, 1) | β’ Internal type for the replication oplog β’ not for date storage, use Date instead | ||
{ pop: Long("7800000") } | β’ 64-bit signed integer β’ Long() in mongosh, legacy alias NumberLong()β’ a bare number too big for Int32 becomes a Double, not a Long | ||
{ amt: Decimal128("9.99") } | β’ 128-bit decimal floating point, 34 digits of precision β’ exact decimal values, the recommended type for money | ||
UUID("3b241101-e2bb-4255-8caf-4136c566a962") | β’ Stored as Binary subtype 4 β’ 16 bytes as BinData against 36 as a string, keeping the _id index smaller | ||
{ lo: MinKey(), hi: MaxKey() } | β’ Sentinels that compare lower/higher than every other type β’ exist primarily for internal use |