Courseiva

C100DEV MongoDB Overview and Document Model Practice Question

A developer stores product documents in a MongoDB collection. Some documents include a nested details object with a warranty subfield, while others do not. The developer needs to retrieve only the documents where details.warranty equals the string "2 years". Which query correctly targets that nested field?

⚠ Common exam trap

The trap here is writing the nested field as an embedded document equality match, which requires the entire subdocument to match exactly and silently misses documents with extra fields.

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.products.find({ "details.warranty": "2 years" })

Dot notation is the correct way to query a field inside an embedded document. Writing the path as a quoted string, such as details.warranty, tells MongoDB to look inside the details object for the warranty field and compare its value. This approach uses indexes when available and returns only documents whose nested field equals the requested value.

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.products.find({ details: { warranty: "2 years" } })

    Why it's wrong here

    An embedded document equality match requires the entire details object to match exactly, including field order and all other subfields. A document whose details object contains additional fields would not match even if warranty equals the target string. This query is too strict and would miss valid documents, so it does not satisfy the requirement.

  • ✗

    db.products.find({ $where: "this.details.warranty === '2 years'" })

    Why it's wrong here

    The $where operator executes JavaScript on the server for each document, which is slow, cannot use indexes effectively, and is discouraged for ordinary queries. It also introduces scripting overhead and security concerns. Using dot notation in a normal query is simpler, indexable, and the correct approach for matching a nested field value.

  • ✓

    db.products.find({ "details.warranty": "2 years" })

    Why this is correct

    Dot notation reaches into embedded documents, so the path details.warranty matches the warranty field inside the details object. Quoting the path is required because it contains a dot. This query returns exactly the documents whose nested warranty value equals the string, which is the requested result and the standard way to query embedded fields in MongoDB.

  • ✗

    db.products.find({ details: { $elemMatch: { warranty: "2 years" } } })

    Why it's wrong here

    $elemMatch is designed for arrays of documents, matching when at least one array element satisfies the conditions. Since details is a single embedded object rather than an array, $elemMatch does not apply and would not match the intended documents. This option confuses array element matching with embedded document field matching.

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 →

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.