Courseiva
Aggregation Framework →hardMultiple Choice

C100DEV Aggregation Framework Practice Question

Exhibit

db.collection.aggregate([ { $group: { _id: "$category", total: { $sum: "$price" } } } ])

Refer to the exhibit. What happens to documents in the collection that do not contain the 'category' field?

⚠ Common exam trap

Candidates often assume documents missing the grouping field are excluded from the results, not realizing that MongoDB treats missing fields as null and groups them together under the null key.

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

✓

They are assigned to a group with _id: null.

When grouping by a field, MongoDB treats missing fields or null values as having the value 'null'. Therefore, all documents lacking a 'category' field will be grouped together under the ID 'null'. This behavior is consistent and ensures no documents are silently dropped during a $group operation, allowing developers to identify and handle data quality issues where mandatory fields might be missing from certain records.

Answer analysis

Option-by-option breakdown

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

  • ✗

    They are excluded from the results.

    Why it's wrong here

    MongoDB does not silently drop documents during a $group stage. If the grouping field is missing, the engine assigns them to a group identified by 'null'. This ensures data integrity and prevents the accidental loss of records that simply lack specific field values in their current schema structure.

  • ✓

    They are assigned to a group with _id: null.

    Why this is correct

    When the field specified in the _id expression of a $group stage is missing, MongoDB treats the value as null. All such documents are subsequently aggregated into a single group where the _id field is set to null, effectively capturing all documents that lack the 'category' key.

  • ✗

    The aggregation throws an error.

    Why it's wrong here

    The aggregation engine does not require fields to be present in every document. It gracefully handles missing fields by substituting them with a null value for the purpose of the group identification. Consequently, the query runs successfully without error, aggregating the incomplete documents into a null group.

  • ✗

    They are grouped individually as unique documents.

    Why it's wrong here

    Grouping logic aggregates documents based on the equality of the _id expression. Because all missing fields evaluate to null, they are considered equal in the context of the grouping operation. Therefore, they are merged into a single bucket rather than being treated as separate individual entries.

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.