Courseiva

C100DEV MongoDB Overview and Document Model Practice Question

A developer is writing a Node.js script that inserts a user document into a MongoDB 7.0 collection. The document includes an _id field whose value is generated by the driver as an ObjectId. A teammate asks why the _id field is present even though the insertOne call did not specify it. Which statement best explains the behavior of _id in MongoDB?

⚠ Common exam trap

The trap here is assuming _id is optional or that the server generates it after the insert, rather than recognizing that the driver creates the ObjectId client-side before sending the command.

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

✓

The _id field is mandatory in every document, and if the client omits it the driver generates an ObjectId before sending the insert.

MongoDB mandates a unique _id in every stored document and automatically builds a unique index on that field. Official drivers generate an ObjectId on the client when the application does not provide one, so the field is present in the inserted document without explicit developer action. This guarantees each document can be uniquely identified and located efficiently.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✗

    The _id field is added by the mongod server after the insert completes, and the client must run a find to retrieve the generated value.

    Why it's wrong here

    The server does not append _id after the fact. Drivers such as the Node.js driver generate the ObjectId on the client before the insert command is sent, and the insertedId is returned in the write result. A follow-up find is not required to learn the value, so this description of server-side generation is inaccurate.

  • ✗

    The _id field is optional and is only populated when the collection has a unique index defined by the developer.

    Why it's wrong here

    Every MongoDB document stored in a collection must contain a unique _id field, and MongoDB automatically creates a unique index on _id when the collection is created. It is not optional, and the index is created by the server rather than by the developer, so this statement misrepresents how _id works in a standard collection.

  • ✗

    The _id field is only required for capped collections and time series collections, while normal collections allow documents without it.

    Why it's wrong here

    All collections require a unique _id for each document, including capped and time series collections, which have additional restrictions on updates and deletes. There is no category of ordinary collection that permits documents lacking _id, so this statement misstates the rule and would lead a developer to design an invalid insert.

  • ✓

    The _id field is mandatory in every document, and if the client omits it the driver generates an ObjectId before sending the insert.

    Why this is correct

    MongoDB requires a unique _id in every document stored in a collection. When an application does not supply one, the official drivers generate an ObjectId client-side and include it in the insert command, so the server receives a document that already has an _id. This is why the field appears even though the code never set it explicitly.

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 →

How Courseiva writes practice questions · Editorial policy

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.