MongoDB Certified Developer Associate Exam-style mock test
MongoDB Developer Associate Practice Exams|Practice test
Full explanations
Exam format
Pass line 70%
33 USD One-time · lifetime access
Enroll →
Sample questions
Example1 · CRUD Operations
A fintech backend engineer needs to add several new ledger entries to the 'transactions' collection in a single command, and wants MongoDB to continue processing the remaining documents even if one of them triggers a duplicate key error. Which approach meets this requirement?
✓Call insertMany with the array of documents and pass the option ordered set to false
Correct. With ordered set to false, MongoDB attempts every document and reports errors without stopping at the first failure.
・Call insertOne repeatedly inside a loop and ignore each thrown error
Incorrect. Looping over insertOne works but is inefficient and is not the intended single-command bulk insert.
・Call insertMany with the array of documents and pass the option ordered set to true
Incorrect. ordered set to true stops processing at the first error, so later documents are skipped.
・Call insertMany with the array of documents and no options, since it defaults to continuing on errors and skips any document that violates a constraint automatically for you
Incorrect. The default for insertMany is ordered true, which halts on the first error rather than continuing.
Explanation
insertMany defaults to ordered execution; setting ordered to false lets the operation continue past individual failures.
Example2 · Indexes
A fintech backend team notices that a query filtering transactions by a single field, accountId, performs a full collection scan. Which index best supports fast equality lookups on this field?
✓db.transactions.createIndex({ accountId: 1 })
Correct. A single-field ascending index on accountId directly supports equality lookups on that field and eliminates the collection scan.
・db.transactions.createIndex({ accountId: 1, amount: 1, currency: 1, createdAt: -1 })
Incorrect. This compound index adds unnecessary fields for a simple single-field equality query and is broader than needed.
・db.transactions.createIndex({ accountId: "text" })
Incorrect. A text index is designed for string search of words in content, not equality matching of an identifier.
・db.transactions.createIndex({ accountId: "2dsphere" })
Incorrect. A 2dsphere index supports geospatial queries, not equality lookups on an account identifier.
Explanation
A single-field index on the queried field is the minimal and correct choice to support an equality filter.
Example3 · Data Modeling
A fintech team stores each customer's account profile with their last five login events, which are almost always read together on the dashboard and rarely change. Which modeling approach best fits this access pattern?
✓Embed the five login events as an array inside the customer document
Correct. Data read together and bounded in size is a classic case for embedding, giving a single-document read.
・Store each login event in a separate collection keyed by customer id
Incorrect. A separate collection forces extra queries for data always read together.
・Create a many-to-many junction collection linking customers to logins
Incorrect. A junction collection suits true many-to-many relationships, not a bounded owned list.
・Keep logins in a separate collection and join them at read time using repeated lookups across shards
Incorrect. Repeated lookups add latency and cost for data that is small and always read together.
Explanation
When related data is bounded, read together, and rarely changes, embedding yields the fastest single-document access.
Example4 · Aggregation Framework
A developer on a healthcare data platform writes a pipeline that filters a 50-million-document 'vitals' collection on an indexed 'patientId', then groups the matches by 'wardId'. To let the index on 'patientId' be used, where should the $match stage appear?
・After the $group so the grouped output is filtered
Incorrect. Filtering after $group means every document is scanned and the index cannot be used.
✓Before the $group, as the first stage
Correct. A $match placed first can use the 'patientId' index to limit documents before grouping.
・Inside the $group as an accumulator argument
Incorrect. $group accumulators aggregate values and do not perform index-based filtering.
・Wrapped in a $facet so both stages run independently against the same input set
Incorrect. $facet runs sub-pipelines but does not by itself move the filter ahead of the scan.
Explanation
Placing $match early lets the query engine use an index to reduce the working set before later stages run.
Example5 · Drivers, Tools, and Server Fundamentals
A healthcare data platform team is building a patient-intake microservice in Node.js that will write admission records to MongoDB. Which component should the team add to the service so that it can communicate with the MongoDB server using idiomatic JavaScript?
✓The official MongoDB Node.js driver package installed from npm
Correct. The official Node.js driver is the supported library that lets application code speak the MongoDB wire protocol idiomatically.
・The mongosh shell binary invoked as a child process for every query
Incorrect. mongosh is an interactive administrative shell, not an application driver for production request handling.
・A custom TCP socket layer that hand-serializes BSON on each request to the cluster
Incorrect. Writing a raw socket and BSON layer by hand duplicates driver work and is not the recommended integration path.
・The MongoDB Compass desktop application bundled into the container image
Incorrect. Compass is a GUI for exploration, not a programmatic driver embedded in a running service.
Explanation
Applications connect to MongoDB through the official language driver; for Node.js that is the npm-published driver.
Example6 · CRUD Operations
A developer on the healthcare data platform must add a batch of 500 new patient intake records to the patients collection in a single call, returning every inserted _id. Which operation should the developer use?
✓db.patients.insertMany(docs)
Correct. insertMany accepts an array and inserts all documents in one call, returning the inserted _id values.
・db.patients.insertOne(docs)
Incorrect. insertOne inserts a single document and rejects an array of many records.
・db.patients.updateMany({}, docs)
Incorrect. updateMany modifies existing documents and does not create 500 new ones.
・db.patients.replaceOne({}, docs)
Incorrect. replaceOne swaps one matched document and cannot insert a batch.
Explanation
insertMany is the method designed to add an array of multiple documents at once and report their inserted identifiers.
Example7 · CRUD Operations
The catalog team at an e-commerce service must add three new products to the 'products' collection in a single command, and each product must receive its own generated _id. Which operation should they run?
✓db.products.insertMany([doc1, doc2, doc3])
Correct. insertMany accepts an array of documents and inserts each one, generating an _id for any document that lacks one.
・db.products.insertOne([doc1, doc2, doc3])
Incorrect. insertOne inserts a single document; passing an array stores one document containing that array.
・db.products.save([doc1, doc2, doc3], {ordered: true, writeConcern: {w: 'majority'}})
Incorrect. save is deprecated and does not take an array of documents to insert in this form.
・db.products.addMany([doc1, doc2, doc3])
Incorrect. addMany is not a MongoDB collection method, so this command fails.
Explanation
insertMany is the correct method for adding multiple documents at once, with automatic _id generation per document.
Example8 · CRUD Operations
A storefront page must list every product in the 'products' collection whose 'price' field is at least 50 and at most 200. Which filter returns exactly that set?
✓db.products.find({price: {$gte: 50, $lte: 200}})
Correct. Combining $gte and $lte on the same field matches values in the inclusive range 50 through 200.
・db.products.find({price: {$min: 50, $max: 200}})
Incorrect. $min and $max are not query comparison operators for filtering ranges.
・db.products.find({price: {$between: [50, 200]}})
Incorrect. There is no $between operator in the MongoDB query language.
・db.products.find({price: {$gt: 50}}, {price: {$lt: 200}})
Incorrect. The second object is misused as a projection and $gt/$lt would exclude the boundary values.
Explanation
An inclusive range is expressed by applying $gte and $lte together within one field predicate.
Example9 · CRUD Operations
When a customer buys one unit of a product, the service must reduce that product's 'stock' field by 1 for the matching SKU. Which update expression performs this decrement?
✓db.products.updateOne({sku: 'A1'}, {$inc: {stock: -1}})
Correct. $inc with a value of -1 atomically decreases the numeric stock field by one.
・db.products.updateOne({sku: 'A1'}, {$set: {stock: stock - 1}})
Incorrect. $set cannot reference the existing field value like 'stock - 1' in a standard update.
・db.products.updateOne({sku: 'A1'}, {$dec: {stock: 1}})
Incorrect. There is no $dec update operator in MongoDB.
・db.products.updateOne({sku: 'A1'}, {stock: {$subtract: 1}})
Incorrect. $subtract is an aggregation expression and is not valid as a top-level update operator here.
Explanation
Decrementing a numeric field is done with $inc using a negative value.
Example10 · CRUD Operations
An IoT gateway buffers readings from 500 temperature sensors and needs to write them all to the 'readings' collection in one trip to reduce network round trips. Which operation should the gateway use to insert the whole batch?
・db.readings.insertOne({ sensors: [...] })
Incorrect. insertOne writes a single document, so wrapping 500 readings in one array field creates one document, not 500 separate reading documents.
✓db.readings.insertMany(docsArray)
Correct. insertMany accepts an array of documents and inserts them all in a single call, which is exactly the batch behavior the gateway needs.
・db.readings.updateMany({}, { $push: { docs: docsArray } })
Incorrect. updateMany modifies existing documents and will not create new reading documents when the collection has no matching records.
・db.readings.save(docsArray)
Incorrect. save is deprecated and never accepted an array of documents for bulk insertion.
Explanation
insertMany is the purpose-built method for inserting an array of documents in one operation, minimizing round trips for the sensor batch.
Example11 · CRUD Operations
A dashboard must list all telemetry readings where 'temperature' is strictly greater than 75 degrees. Which query document correctly expresses this filter?
・{ temperature: { $gte: 75, $lte: 200 } }
Incorrect. $gte includes readings equal to 75 and the added upper bound still admits the value 75, but the requirement is strictly greater than 75.
✓{ temperature: { $gt: 75 } }
Correct. $gt matches values strictly greater than the specified number, excluding readings that equal 75.
・{ temperature: { $ne: 75, $exists: true } }
Incorrect. $ne combined with an existence check still matches any value not equal to 75, including values below 75, which is not the intended range.
・{ temperature: { $eq: 75, $type: "number" } }
Incorrect. This matches only numeric readings that equal exactly 75 rather than those above it.
Explanation
The $gt operator returns documents whose field value is strictly greater than the comparison value.
Example12 · CRUD Operations
The social app backend needs to store three new posts in the 'posts' collection with a single command, and the operation should stop at the first document that fails to insert. Which call fits?
✓db.posts.insertMany([p1, p2, p3])
Correct. insertMany accepts an array and by default ordered:true stops at the first failure.
・db.posts.insertOne([p1, p2, p3])
Incorrect. insertOne inserts a single document, not an array.
・db.posts.insertMany([p1, p2, p3], { ordered: false, writeConcern: { w: 'majority' }, bypassDocumentValidation: true })
Incorrect. ordered:false would continue past failures, which is the opposite of the requirement.
・db.posts.save([p1, p2, p3])
Incorrect. save is not a supported insert method for an array of posts.
Explanation
insertMany with its default ordered:true behavior inserts the array and halts at the first error.
Example13 · CRUD Operations
You must return every post in the 'posts' collection whose 'likes' field is strictly greater than 100. Which filter is correct?
✓db.posts.find({ likes: { $gt: 100 } })
Correct. $gt matches values strictly greater than the given number.
・db.posts.find({ likes: { $gte: 100, $exists: true } })
Incorrect. $gte also includes exactly 100, which is not wanted.
・db.posts.find({ likes: { $eq: 100 } })
Incorrect. This matches only posts with exactly 100 likes.
・db.posts.find({ likes: { $greaterThan: 100, $type: "int" } })
Incorrect. $greaterThan is not a valid MongoDB operator.
Explanation
The $gt operator returns documents whose field value exceeds the comparison value.
Example14 · CRUD Operations
A content management platform needs to store three new blog articles in the 'articles' collection with a single command, and the driver should return the generated _id values for all of them. Which method call should the developer use?
✓db.articles.insertMany([doc1, doc2, doc3])
Correct. insertMany accepts an array of documents, inserts them in one operation, and returns the insertedIds for each.
・db.articles.insertOne([doc1, doc2, doc3])
Incorrect. insertOne inserts a single document; passing an array stores the array as one document rather than three.
・db.articles.bulkInsert(doc1, doc2, doc3)
Incorrect. There is no bulkInsert method in the MongoDB CRUD API for inserting multiple documents this way.
・db.articles.save([doc1, doc2, doc3], {multi: true})
Incorrect. save is deprecated and does not accept a multi option for inserting several documents at once.
Explanation
insertMany is the designated method for inserting an array of documents and returning each generated _id.
Example15 · CRUD Operations
On the content platform, an editor wants every article whose 'status' field equals the string 'published'. Which query returns exactly those documents?
・db.articles.find({status: {$eq: ['published']}})
Incorrect. $eq compares against a single value, so passing an array looks for an array equal to ['published'].
✓db.articles.find({status: 'published'})
Correct. A field set directly to a scalar value performs an implicit equality match on that value.
・db.articles.find({status: {$in: 'published'}})
Incorrect. $in requires an array of candidate values, not a bare string, so this query is invalid.
・db.articles.find({$where: 'this.status = published'})
Incorrect. $where expects a JavaScript expression and this one uses assignment and an undeclared identifier.
Explanation
The simplest equality match sets the field to the desired scalar value directly in the query document.
▶ Try 10 free questions (graded)