C100DEV MongoDB Overview and Document Model Practice Question
A developer is new to MongoDB and is examining a collection of documents. Each document contains fields like `name`, `age`, and `address`, where `address` is a nested document with `street`, `city`, and `zip`. The developer wants to query for all documents where the `city` in the nested `address` document is 'New York'. Which query correctly retrieves these documents?
⚠ Common exam trap
The trap here is using an exact match on the nested document, which requires all fields to match exactly, rather than using dot notation to target a single 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
✓
db.collection.find({ 'address.city': 'New York' })
To query a nested field in MongoDB, you use dot notation within a string, such as `'address.city'`. This allows the query to match documents where the nested `city` field equals 'New York', regardless of other fields in the subdocument. The other options either perform an exact match on the entire subdocument, use invalid syntax, or misuse the `$elemMatch` operator.
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.collection.find({ $elemMatch: { 'address.city': 'New York' } })
Why it's wrong here
The `$elemMatch` operator is designed to match elements within an array. Since `address` is a nested document, not an array, using `$elemMatch` here is inappropriate and would not match any documents. It would only be useful if `address` were an array of subdocuments. Therefore, this query fails to retrieve the desired results.
- ✗
db.collection.find({ address: { city: 'New York' } })
Why it's wrong here
This query uses an exact match on the entire `address` subdocument. It would only return documents where the `address` field is exactly `{ city: 'New York' }`, meaning no other fields like `street` or `zip` are present. Since the actual documents have additional fields in the nested document, this query would not match any of them.
- ✓
db.collection.find({ 'address.city': 'New York' })
Why this is correct
This query uses dot notation to target the `city` field within the nested `address` document. It correctly matches documents where the nested `city` value is 'New York', regardless of other fields in the subdocument. Dot notation is the standard way to query nested fields in MongoDB, allowing precise access to embedded document properties.
- ✗
db.collection.find({ address.city: 'New York' })
Why it's wrong here
This syntax is invalid in MongoDB. When querying nested fields, the field path must be enclosed in quotes if it contains a dot, like `'address.city'`. Without quotes, the JavaScript parser would interpret `address.city` as an attempt to access a property of an object, leading to a syntax error or unexpected behavior. The correct approach uses a string with dot notation.
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.