C100DEV MongoDB Overview and Document Model Practice Question
A developer is using the MongoDB Node.js driver to insert a document into a collection. The document includes a field `_id` set to a custom string value. After the insert, the developer checks the returned result and notices that the `insertedId` matches the custom string. What does this indicate about MongoDB's handling of the `_id` field?
⚠ Common exam trap
The trap here is thinking that `_id` must be an ObjectId, when in fact MongoDB allows any BSON type except arrays for the `_id` field.
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
✓
MongoDB automatically generates an ObjectId for the `_id` field if it is not provided, but if provided, it must be unique within the collection.
The `_id` field is the primary key for MongoDB documents. If omitted, the driver generates an ObjectId; if provided, it can be any BSON type except an array, but it must be unique within the collection. MongoDB automatically creates a unique index on `_id`. The scenario confirms that a custom string was accepted and used as the `_id`, demonstrating this flexibility.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
MongoDB automatically generates an ObjectId for the `_id` field if it is not provided, but if provided, it must be unique within the collection.
Why this is correct
In MongoDB, every document must have an `_id` field that acts as a primary key. If the `_id` is not specified, the driver generates an ObjectId. If a custom value is provided, it can be any BSON type except an array, but it must be unique within the collection. The insert succeeds only if the custom `_id` does not already exist, ensuring uniqueness.
- ✗
The `_id` field is always an ObjectId and cannot be overridden with a custom value.
Why it's wrong here
This is false because MongoDB allows the `_id` field to be of any BSON type other than an array. Developers can supply a custom string, integer, or even a subdocument as the `_id`. The ObjectId is the default, but it is not mandatory. The scenario demonstrates that a custom string was accepted, proving that overriding is possible.
- ✗
The `_id` field is only unique per shard, not across the entire collection.
Why it's wrong here
Uniqueness of the `_id` field is enforced across the entire collection, regardless of sharding. In a sharded cluster, the `_id` index is unique across all shards. MongoDB ensures that no two documents in the same collection can have the same `_id`. This is a core guarantee for the primary key, so this statement is incorrect.
- ✗
MongoDB automatically indexes the `_id` field only if it is an ObjectId.
Why it's wrong here
MongoDB always creates a unique index on the `_id` field by default, regardless of its data type. Whether the `_id` is an ObjectId, string, or any other type, the index is automatically created. This ensures fast lookups by `_id` and enforces uniqueness. The index is not conditional on the type of the `_id` value.
About these practice questions
This C100DEV question is part of Courseiva's 259-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. 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.