Core MongoDB Functionality
Core MongoDB functionality is shared across every language version of the exam. It tests document modelling, CRUD and aggregation code, index selection that actually gets used, and reasoning about replica sets, sharding, and transactions independent of the driver.
Modelling and CRUD
Documents are BSON; _id is generated as an ObjectId when omitted and is immutable. Update with operators - $set, $unset, $inc, $push, $addToSet, $pull - and arrayFilters for nested arrays. updateOne(filter, update, {upsert:true}) inserts when nothing matches; add $setOnInsert so a retried upsert does not clobber existing fields. Write concern w:"majority" waits for replication; read concern "majority" returns majority-acknowledged data.
Indexes
Compound index {a:1,b:1,c:1} serves filters on a, a+b, a+b+c - the prefix rule - never b alone. Order fields Equality, Sort, Range. Multikey indexes cover arrays, and two conditions on one element need $elemMatch. Covered queries return only indexed fields and skip FETCH; partial indexes hold a filtered subset, TTL indexes expire documents, and unique indexes enforce constraints.
Aggregation
Stages run in order. Put $match and $sort before $group so they can use indexes; run $lookup after reducing data. Each stage is capped at 100 MB unless you set allowDiskUse. $facet runs sub-pipelines on the same input.
Replication, sharding, transactions
A replica set has one primary and secondaries; reads default to the primary. Shard keys are immutable and set chunk distribution - high-cardinality, non-monotonic keys avoid hotspots. Multi-document transactions require a replica set or sharded cluster, run inside a session, and default to a 60-second lifetime.
Worked example
Collection orders holds {status, ts, total}. The query find({status:"shipped", total:{$gt:100}}).sort({ts:-1}) has equality on status, a sort on ts, and a range on total, so build {status:1, ts:-1, total:1}. explain("executionStats") should show IXSCAN with totalKeysExamined near nReturned and no SORT stage. Indexing {ts:1,status:1} instead forces a blocking in-memory sort.
Traps
Prefix errors are the classic mark-loser. $regex is index-friendly only when left-anchored; case-insensitive regex ignores the index unless a collation is used. Without $elemMatch, two conditions on one array may match different elements. A $match placed after $group cannot use an index.