MongoDB Associate Developer study materials
MongoDB Associate Developer study resources

MongoDB Associate Developer practice questions

One question at a time. Build your MongoDB Associate Developer understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1MongoDB Overview and Architecture

Which MongoDB structure directly holds a set of related documents, serving a role similar to a table in a relational database?

  1. A collection Correct answer.
  2. A shard
  3. A database
  4. A namespace

Explanation

Documents are stored inside collections, and each collection belongs to exactly one database. A collection groups related documents, which is the conceptual counterpart of a relational table.

Question 2MongoDB Overview and Architecture

In what binary format does MongoDB store and transmit documents?

  1. XML
  2. MessagePack
  3. Protobuf
  4. BSON Correct answer.

Explanation

BSON is a binary-encoded superset of JSON that adds types such as dates, ObjectIds, and binary data. Its length-prefixed layout lets the server skip over fields quickly without parsing the whole document.

Question 3MongoDB Overview and Architecture

What is the maximum size of a single BSON document that MongoDB will store?

  1. 32 MB
  2. 8 MB
  3. 16 MB Correct answer.
  4. 4 MB

Explanation

MongoDB enforces a 16 megabyte limit per BSON document. Data that exceeds this must be split across multiple documents or stored through GridFS.

Question 4MongoDB Overview and Architecture

A document is inserted with insertOne and no _id field is supplied. What does the driver do?

  1. It assigns the next value from a global integer sequence
  2. It generates an ObjectId and adds _id to the document Correct answer.
  3. It stores the document with _id set to null
  4. It rejects the insert because _id is mandatory

Explanation

Every stored document needs a unique _id. When the field is missing, the driver creates a new ObjectId on the client and adds it as the first field before sending the insert.

Question 5MongoDB Overview and Architecture

Which process is the core MongoDB server that stores data and handles reads and writes?

  1. mongostat
  2. mongod Correct answer.
  3. mongosh
  4. mongos

Explanation

mongod is the database server process that owns the data files, runs the storage engine, and executes queries. The other programs are a router, a shell, and a monitoring utility respectively.

Question 6MongoDB Overview and Architecture

Which MongoDB feature stores files that exceed the 16 MB document limit by splitting them into chunks?

  1. Time series collections
  2. Capped collections
  3. Change streams
  4. GridFS Correct answer.

Explanation

GridFS divides a large file into chunks stored as documents across two collections, one holding chunk data and one holding file metadata, so files of any size can be stored.

Question 7MongoDB Overview and Architecture

Which offering is MongoDB's fully managed cloud database service?

  1. MongoDB Atlas Correct answer.
  2. mongosh
  3. MongoDB Database Tools
  4. MongoDB Compass

Explanation

Atlas is the hosted, fully managed service that provisions and operates deployments on major cloud providers, including backups, monitoring, and scaling.

Question 8MongoDB Overview and Architecture

Which tool provides an interactive JavaScript shell for running commands against a MongoDB deployment?

  1. mongos
  2. Compass
  3. mongosh Correct answer.
  4. mongod

Explanation

mongosh connects to a deployment and evaluates JavaScript and database commands interactively. Compass is the graphical equivalent, while mongod and mongos are server processes.

Question 9MongoDB Overview and Architecture

A replica set primary becomes unreachable. What happens if a majority of voting members can still communicate with each other?

  1. An arbiter is promoted because it holds no stale data
  2. An election is held and a secondary is promoted to primary Correct answer.
  3. Secondaries continue accepting writes until the old primary returns
  4. The set becomes read-only until an administrator intervenes

Explanation

Members monitor each other with heartbeats. When the primary is lost and a majority of voters can communicate, they elect a new primary from an eligible secondary and writes resume automatically.

Question 10MongoDB Overview and Architecture

What role does an arbiter play in a replica set?

  1. It serves reads on behalf of busy secondaries
  2. It routes client requests to the correct shard
  3. It keeps a full copy of the data set for failover
  4. It votes in elections but stores no data Correct answer.

Explanation

An arbiter is a lightweight member that participates in elections and can provide the extra vote needed for a majority, but it holds no data and cannot become primary.

Question 11MongoDB Overview and Architecture

In a sharded cluster, which component receives client requests and routes them to the appropriate shards?

  1. The mongos routers Correct answer.
  2. The config servers
  3. The shard primaries
  4. The balancer

Explanation

mongos processes act as query routers: they consult cluster metadata from the config servers to target the correct shards and then merge the results for the client.

Question 12MongoDB Overview and Architecture

Which background process moves chunks between shards to keep data evenly distributed?

  1. The oplog applier
  2. The balancer Correct answer.
  3. The config server primary
  4. The mongos query router

Explanation

The balancer compares chunk counts per shard and migrates chunks to correct imbalances. mongos processes may carry out a migration, but the balancing policy drives it.

Question 13MongoDB Overview and Architecture

What index requirement must be met before a collection can be sharded on a given key?

  1. An index whose key pattern starts with the shard key must exist Correct answer.
  2. No index is required because the shard key is tracked separately
  3. A unique index on _id alone must exist
  4. A text index on the shard key fields must exist

Explanation

A collection can be sharded only if an index supports the shard key, meaning its key pattern begins with the shard key fields. That index may already exist or be created by the shard command.

Question 14MongoDB Overview and Architecture

Which read preference sends reads to the primary when it is available and to a secondary only when it is not?

  1. primaryPreferred Correct answer.
  2. secondaryPreferred
  3. primary
  4. nearest

Explanation

primaryPreferred falls back to a secondary only when the primary is unavailable, preserving primary reads in normal operation while still allowing reads during failover.

Question 15MongoDB Overview and Architecture

What does write concern { w: "majority" } require before the write is acknowledged?

  1. That the primary has written the operation to its journal only
  2. That the primary has applied the write in memory
  3. That a majority of voting members have acknowledged the write Correct answer.
  4. That every data-bearing member has applied the write

Explanation

A majority write concern acknowledges the write once more than half of the voting replica set members have applied it, so the write survives the loss of a minority of members.

Question 16MongoDB Overview and Architecture

Which storage engine does MongoDB use by default?

  1. MMAPv1
  2. B-tree
  3. In-Memory
  4. WiredTiger Correct answer.

Explanation

WiredTiger has been the default storage engine since MongoDB 3.2, providing document-level concurrency control, compression, and checkpointing.

Question 17MongoDB Overview and Architecture

By default, how frequently does WiredTiger create a checkpoint?

  1. Every second
  2. Every 10 seconds
  3. Every 60 seconds Correct answer.
  4. Every 5 minutes

Explanation

WiredTiger writes a consistent checkpoint of the data files every 60 seconds by default, while the journal protects writes made between checkpoints.

Question 18MongoDB Overview and Architecture

Which index type causes MongoDB to automatically delete documents after a specified time?

  1. A wildcard index
  2. A partial index
  3. A sparse index
  4. A TTL index Correct answer.

Explanation

A TTL index uses a date field together with the expireAfterSeconds option, and a background thread removes documents whose date value is older than the threshold.

Question 19MongoDB Overview and Architecture

What capability do change streams provide to an application?

  1. Cache query results in memory until the next write
  2. Automatically shard a collection as it grows
  3. Receive real-time notifications of data changes Correct answer.
  4. Read the raw oplog directly from any secondary

Explanation

Change streams expose a resumable cursor of insert, update, delete, and other events, letting applications react to data changes without reading the oplog themselves.

Question 20MongoDB Overview and Architecture

On which deployments can multi-document transactions be used?

  1. Sharded clusters only
  2. Replica sets and sharded clusters Correct answer.
  3. Any deployment, including standalone servers
  4. Standalone servers only

Explanation

Transactions depend on the oplog, so they require a replica set, and they also work in sharded clusters where they can span multiple shards. Standalone servers do not support them.

Question 21MongoDB Overview and Architecture

Which description matches the composition of the default 12-byte ObjectId?

  1. A 4-byte timestamp, a 5-byte random value, and a 3-byte counter Correct answer.
  2. A 4-byte counter, a 4-byte machine hash, and a 4-byte timestamp
  3. A 16-character hex string stored as a UUID subtype
  4. An 8-byte timestamp followed by a 4-byte random value

Explanation

An ObjectId consists of a 4-byte Unix timestamp in seconds, a 5-byte per-process random value, and a 3-byte incrementing counter, which makes values roughly ordered by creation time.

Question 22MongoDB Overview and Architecture

A replica set has five voting members. Three become unreachable and the remaining two can communicate with each other. What is the outcome?

  1. The reachable members accept writes using w: 1
  2. The reachable members continue with the last known primary's state
  3. No primary can be elected and the set cannot accept writes Correct answer.
  4. The two reachable members elect one of themselves as primary

Explanation

Elections need a majority of voting members, which for five members is three. With only two reachable voters there is no majority, so no primary can be elected and writes fail until connectivity is restored.

Question 23MongoDB Overview and Architecture

What is a distinguishing property of a clustered collection?

  1. It deletes the oldest documents once it is full
  2. It allows only one document per shard key value
  3. It stores documents in _id order with no separate _id index Correct answer.
  4. It keeps every document in memory and never writes to disk

Explanation

Clustered collections store documents physically ordered by _id through a clustered index, which speeds up _id range and equality lookups and removes the need for a separate _id index.

Question 24MongoDB Overview and Architecture

Which statement describes a time series collection?

  1. It groups measurements into buckets by time and metadata Correct answer.
  2. It requires a single document per series and updates it in place
  3. It stores each measurement in a collection named after its timestamp
  4. It converts every insert into an update on a capped collection

Explanation

Time series collections group measurements into bucket documents keyed by time and metadata, which reduces storage overhead and speeds up time-range queries while still accepting ordinary inserts.

Question 25MongoDB Overview and Architecture

Which property applies to a hashed shard key?

  1. It works only with compound shard keys of two or more fields
  2. It preserves ordering so range queries target one shard
  3. It requires shard key values to be unique for all documents
  4. It spreads data evenly but range queries hit all shards Correct answer.

Explanation

A hashed shard key indexes a hash of the field value, which spreads inserts evenly across shards. Because hashing destroys ordering, range queries on the underlying field generally have to be broadcast to every shard.

Question 26MongoDB Overview and Architecture

What does the oplog in a MongoDB replica set contain?

  1. Authentication credentials for cluster members
  2. Query plans cached by the query optimizer
  3. Periodic snapshots of the entire data directory
  4. An ordered record of write operations Correct answer.

Explanation

The oplog is a capped collection that records the ordered stream of write operations applied to the data set. Secondary members continuously read and apply these entries to stay consistent with the primary.

Question 27CRUD Operations

A developer calls insertOne on a collection and inspects the returned value. What does that result contain when the write is acknowledged?

  1. It returns a result object with the insertedId. Correct answer.
  2. It returns the full inserted document as stored in the collection.
  3. It returns a cursor positioned on the new document.
  4. It returns the number of documents in the collection after the insert.

Explanation

insertOne reports the outcome of the write in a result document. When the write is acknowledged, that result includes insertedId, the _id value generated or supplied for the new document. The stored document itself is not returned.

Question 28CRUD Operations

A query is run with findOne and no document matches the filter. What does findOne return?

  1. An empty document.
  2. An empty cursor.
  3. null. Correct answer.
  4. It throws an error.

Explanation

findOne returns a single document when a match exists and null when nothing matches. A missing match is an ordinary outcome, not an error condition.

Question 29CRUD Operations

The field status holds a single string value. Which filter matches documents whose status is either "open" or "closed"?

  1. {status: {$eq: ["open", "closed"]}}
  2. {status: {$in: ["open", "closed"]}} Correct answer.
  3. {status: {$or: ["open", "closed"]}}
  4. {status: {$all: ["open", "closed"]}}

Explanation

$in matches documents whose field value equals any one of the values in the supplied array. It is the field-level operator designed for membership tests.

Question 30CRUD Operations

Which filter matches every document whose score is between 50 and 100, including both endpoints?

  1. {score: {$gt: 50, $lt: 100}}
  2. {score: {$gte: 50, $lt: 100}}
  3. {score: {$gte: 50, $lte: 100}} Correct answer.
  4. {score: {$gt: 50, $lte: 100}}

Explanation

$gte and $lte are inclusive comparisons, so combining them on one field expresses a closed range. Multiple operators on the same field are ANDed together.

Question 31CRUD Operations

Which update document sets the field status to "active" on a matched document while leaving its other fields unchanged?

  1. {$replace: {status: "active"}}
  2. {status: "active"}
  3. {$set: {status: "active"}} Correct answer.
  4. {$update: {status: "active"}}

Explanation

$set modifies only the named fields and preserves everything else in the document. Update documents must use update operators; a bare document is not a valid update specification.

Question 32CRUD Operations

Which update operator increases the numeric field views by 1 relative to its current value?

  1. {$mul: {views: 1}}
  2. {$set: {views: 1}}
  3. {$push: {views: 1}}
  4. {$inc: {views: 1}} Correct answer.

Explanation

$inc adds the supplied amount to the existing numeric value and creates the field if it is absent. It performs an atomic in-place increment rather than an assignment.

Question 33CRUD Operations

A collection has five documents that match the filter passed to deleteOne. How many documents does the operation remove?

  1. A single matching document. Correct answer.
  2. None, because an empty filter is not allowed.
  3. All matching documents.
  4. It depends on the write concern.

Explanation

deleteOne removes at most one document, choosing a single match even when many qualify. Removing every match requires deleteMany.

Question 34CRUD Operations

Which call returns the unique values of the field category across the documents that match an optional filter?

  1. db.items.find({}, {category: 1})
  2. db.items.countDocuments({category: {$exists: true}})
  3. db.items.distinct("category") Correct answer.
  4. db.items.findOne({}, {category: 1})

Explanation

distinct returns an array of the unique values of a field for the documents matching the filter. The other calls return documents or counts rather than a set of values.

Question 35CRUD Operations

insertMany is called with {ordered: false} on a batch where a document in the middle fails validation. What is the outcome?

  1. MongoDB retries the failing document automatically.
  2. The remaining documents are still inserted and the errors are reported. Correct answer.
  3. Insertion stops at the failing document and earlier documents remain.
  4. The whole batch is rolled back and nothing is inserted.

Explanation

With ordered: false the server keeps processing the batch after a failure and returns all failures in the write errors. Documents that were valid are still inserted.

Question 36CRUD Operations

Which projection document passed to find causes an error?

  1. {name: 1, price: 0} Correct answer.
  2. {name: 0, price: 0}
  3. {name: 1, price: 1}
  4. {name: 1, _id: 0}

Explanation

A projection cannot mix included and excluded fields, with the single exception of _id, which may be excluded inside an inclusion projection. All other fields must be treated consistently.

Question 37CRUD Operations

Documents in the orders collection hold an items array of subdocuments with sku and qty fields. Which filter requires one single array element to have sku "a" and qty of at least 5?

  1. {"items.sku": "a", "items.qty": {$gte: 5}}
  2. {items: {sku: "a", qty: {$gte: 5}}}
  3. {items: {$elemMatch: {sku: "a", qty: {$gte: 5}}}} Correct answer.
  4. {items: {$all: [{sku: "a"}, {qty: {$gte: 5}}]}}

Explanation

$elemMatch applies all of its conditions to the same array element, which is what "one element satisfies both" requires. Plain conditions on array fields can each be satisfied by different elements.

Question 38CRUD Operations

updateOne({email: "[email protected]"}, {$set: {active: true}}, {upsert: true}) finds no matching document. What does MongoDB do?

  1. Nothing is changed and no document is created.
  2. It creates a document containing only _id and active: true.
  3. It raises an error because no document matched.
  4. It creates a document containing the filter's equality field plus active: true. Correct answer.

Explanation

With upsert: true a missing match causes an insert. The new document is built from equality conditions in the filter combined with the fields produced by the update operators; non-equality filter expressions are not copied.

Question 39CRUD Operations

replaceOne({_id: 1}, {name: "new"}) succeeds on a document that also had an email field. What happens to that email field?

  1. It is removed, because the replacement becomes the whole document apart from _id. Correct answer.
  2. It is preserved unchanged.
  3. It is set to null.
  4. The operation fails because the replacement omits an existing field.

Explanation

replaceOne substitutes the entire document with the replacement, so any field not present in the replacement no longer exists afterwards. Only _id is carried over.

Question 40CRUD Operations

Which update adds the value "red" to the tags array only when that value is not already an element?

  1. {$set: {tags: "red"}}
  2. {$push: {tags: {$each: ["red"]}}}
  3. {$insert: {tags: "red"}}
  4. {$addToSet: {tags: "red"}} Correct answer.

Explanation

$addToSet treats the array as a set, adding the value only if it is not already present. This prevents duplicate entries without a separate read.

Question 41CRUD Operations

Which option makes findOneAndUpdate return the document as it exists after the modification?

  1. {returnDocument: "before"}
  2. {new: false}
  3. {returnNewDocument: true}
  4. {returnDocument: "after"} Correct answer.

Explanation

findOneAndUpdate accepts returnDocument with the values "before" or "after". Passing "after" returns the post-update version of the document.

Question 42CRUD Operations

A find call is built with sort, skip and limit chained in some order. In what order does the server apply them?

  1. sort, then skip, then limit Correct answer.
  2. limit, then skip, then sort
  3. skip, then sort, then limit
  4. sort, then limit, then skip

Explanation

The server sorts the matching documents first, then skips the requested number of positions in that sorted order, then caps the result with the limit. Chaining order in the driver does not change this.

Question 43CRUD Operations

Which filter matches documents where the embedded field address.city equals "Oslo"?

  1. {address: {city: "Oslo"}}
  2. {"address->city": "Oslo"}
  3. {"address.city": "Oslo"} Correct answer.
  4. {address: {$city: "Oslo"}}

Explanation

Dot notation addresses a field inside an embedded document, so the comparison applies to the nested value. The path must be quoted in JavaScript because it contains a dot.

Question 44CRUD Operations

Which filter matches documents in which the field nickname is present, including documents where its value is null?

  1. {nickname: {$ne: null}}
  2. {nickname: null}
  3. {nickname: {$type: "null"}}
  4. {nickname: {$exists: true}} Correct answer.

Explanation

$exists: true matches any document that contains the field, whatever its value, including an explicit null. It tests presence rather than content.

Question 45CRUD Operations

Which update operator assigns a field only in the case where an upsert results in an insert?

  1. {$setOnInsert: {createdAt: new Date()}} Correct answer.
  2. {$insertOnUpdate: {createdAt: new Date()}}
  3. {$setOnUpsert: {createdAt: new Date()}}
  4. {$set: {createdAt: new Date()}}

Explanation

$setOnInsert applies only during the insert branch of an upsert and is ignored when an existing document is updated. It is commonly used to stamp creation metadata that should never be overwritten.

Question 46CRUD Operations

Which update removes every element equal to "spam" from the tags array?

  1. {$pull: {tags: "spam"}} Correct answer.
  2. {$pop: {tags: "spam"}}
  3. {$remove: {tags: "spam"}}
  4. {$unset: {tags: "spam"}}

Explanation

$pull removes all array elements that match the supplied value or condition, leaving the remaining elements in place. It operates on element values rather than positions.

Question 47CRUD Operations

An updateMany uses {$set: {"grades.$[g].score": 100}} together with arrayFilters: [{"g.score": {$lt: 50}}]. What is the effect on each matched document?

  1. Only the first grades element has its score set to 100, if that score is below 50.
  2. Every grades element has its score set to 100 regardless of its current value.
  3. The update fails because the bracketed identifier requires the positional $ operator.
  4. Every grades element with score below 50 gets score set to 100. Correct answer.

Explanation

The $[<identifier>] form updates every array element that satisfies the matching arrayFilters condition. The identifier links the placeholder in the update path to the filter supplied in the options.

Question 48CRUD Operations

An update document supplied as an array of aggregation stages can do which of the following that classic update operators cannot?

  1. Run as part of a multi-document transaction.
  2. Modify more than one document in a single call.
  3. Compute new field values from other fields of the same document. Correct answer.
  4. Create the target collection when it does not exist.

Explanation

A pipeline update evaluates aggregation expressions, so it can derive new values from existing fields of the same document in one atomic step. Classic operators such as $set can only assign literal values or fixed arithmetic.

Question 49CRUD Operations

A filter of {items: {$elemMatch: {qty: {$gt: 10}}}} is used with the update {$set: {"items.$.status": "low"}}. Which array element is modified?

  1. Every element whose qty is greater than 10.
  2. The element at index 0 regardless of the predicate.
  3. The first element matched by the query predicate. Correct answer.
  4. The last element of the array.

Explanation

The positional $ operator resolves to the index of the first array element matched by the query. Only that single element is updated in each matched document.

Question 50CRUD Operations

db.collection.bulkWrite(ops) is called with no options and one operation fails partway through the list. What is the default behavior?

  1. Remaining operations are skipped and the error is reported. Correct answer.
  2. The failed operation is silently ignored and a warning is logged.
  3. Only the failed operation is skipped and the rest continue.
  4. All operations are retried once.

Explanation

bulkWrite defaults to ordered: true, so operations run in sequence and execution stops at the first error. Errors are surfaced in the result rather than suppressed.