C100DEV CRUD Operations Practice Question
A developer needs to insert a single document into the 'inventory' collection and wants the operation to return the generated _id value in the result. Which method should be used?
⚠ Common exam trap
The trap here is choosing a bulk or deprecated write method for a single-document insert, overlooking that insertOne returns the insertedId directly in its result object.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
db.inventory.insertOne({ item: 'canvas', qty: 100 })
insertOne is the purpose-built method for adding a single document and returns an InsertOneResult whose insertedId field exposes the generated or supplied _id. This satisfies the requirement to obtain the identifier immediately, without a follow-up find or relying on deprecated methods such as save or update.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
db.inventory.insertOne({ item: 'canvas', qty: 100 })
Why this is correct
insertOne inserts a single document and returns an InsertOneResult object that includes the acknowledged flag and the insertedId field. This gives the developer immediate access to the generated _id without an extra query, which is exactly what the scenario requires for a single-document insert.
- ✗
db.inventory.update({ item: 'canvas' }, { qty: 100 }, { upsert: true })
Why it's wrong here
The update method is deprecated in favor of updateOne and updateMany, and it does not return the inserted _id in the same direct manner. Using upsert for a plain insert conflates two operations and complicates error handling. It also requires a filter document, which is unnecessary when the goal is simply to insert and retrieve the new identifier.
- ✗
db.inventory.insertMany([{ item: 'canvas', qty: 100 }])
Why it's wrong here
insertMany is designed for arrays of documents and returns an InsertManyResult containing an array of insertedIds. Although it can insert one document if passed a single-element array, it is not the intended method for a single insert and returns a collection of identifiers rather than a single insertedId, making it a poor fit for the stated requirement.
- ✗
db.inventory.save({ item: 'canvas', qty: 100 })
Why it's wrong here
The save method is deprecated in modern MongoDB drivers and shell versions. It either inserts or replaces depending on whether _id is present, which introduces ambiguity, and it does not provide the same clear single-insert result shape. Using it for a straightforward insert is discouraged and may not be available in newer tooling.
About these practice questions
One of 259 original C100DEV practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official MongoDB exam blueprint
This C100DEV practice question is part of Courseiva's free MongoDB certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the C100DEV exam.