Missing fields and explicit null values represent different states. Queries and indexes may treat them differently, so specify intended matching behavior.
Before you start
You should understand documents, collections and indexes. Sketch representative documents and the reads and writes they must support. MongoDB-specific examples assume a collection with the shown fields; deployment topology, permissions and existing indexes can affect the operational behavior being discussed.
The practical goal is to reason through this situation: A record without archivedAt differs from one explicitly storing null. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.
Step-by-step walkthrough
Step 1: List the three states
Distinguish absent archivedAt, explicit null and a timestamp.
Step 2: Choose matching semantics
A null equality query can match both missing and null.
Step 3: Use presence explicitly
Use $exists when the requirement concerns absence rather than value.
Worked scenario
A record without archivedAt differs from one explicitly storing null.
db.records.find({ archivedAt: { $exists: false } });In mongosh this selects documents lacking the field. It differs from { archivedAt: null }, which also includes explicit null. A timestamp represents another state, so seed all three rather than relying on one example.
Common mistake
A simple null query can include both missing and null fields.
Verify the behavior
Compare absence, null and populated queries against those three seeded documents.
Interview exercise
Match only absent fields.
Answer and reasoning
Use an existence condition and test all three cases: absent, explicit null and a populated value.
Continue learning
Compare the scenario with the MongoDB interview questions and test your understanding with the MongoDB MCQs. For terminology and implementation details, consult the reference material.