Courseiva
Data Modeling →mediumMultiple Choice

C100DEV Data Modeling Practice Question

A financial analytics team stores daily stock snapshots as one document per symbol per day in a collection named 'prices'. Each document contains an array of 60 subdocuments, one per minute, with fields 'minute', 'open', 'close', and 'volume'. The team now needs to compute the hourly average 'close' for a single symbol over a single day. Which aggregation approach is most appropriate for this schema?

⚠ Common exam trap

The trap here is assuming that embedded arrays must be migrated to a flat collection before they can be aggregated on individually.

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

✓

Use $unwind on the minute array, then group by an expression that truncates 'minute' to the hour and average 'close'.

The data is stored in buckets, so per-minute analysis requires expanding the embedded array before grouping. $unwind emits one document per array element, and a subsequent $group can bucket by a truncated hour value and compute the average 'close'. This preserves the storage benefits of embedding while still enabling fine-grained aggregation over the measurements.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Run a $match for the symbol and day, then use $replaceRoot with the minute array to promote each element.

    Why it's wrong here

    $replaceRoot replaces the whole document with a single expression result, so it cannot fan out an array of sixty subdocuments into sixty documents. It would leave the array intact, and averaging 'close' would require further stages anyway. The scenario needs per-minute rows before grouping, which $unwind provides and $replaceRoot does not.

  • ✗

    Use $group with $push to collect all 'close' values into an array, then apply $avg to the array.

    Why it's wrong here

    $avg is an accumulator used inside $group, not an array operator that averages elements of a pushed array. Using $push would collect values but leave the averaging unsolved, and there is no single stage that averages array contents per hour. The hourly grouping also requires a computed key that truncates 'minute', which this approach does not produce.

  • ✓

    Use $unwind on the minute array, then group by an expression that truncates 'minute' to the hour and average 'close'.

    Why this is correct

    Because the minute samples are embedded as an array, $unwind produces one document per minute so that a $group stage can bucket by hour and compute the average 'close'. This matches the Bucket pattern's intent of storing many measurements per document while still allowing per-measurement aggregation without reading other days or symbols.

  • ✗

    Create a separate collection with one document per minute and migrate the data, then aggregate over it.

    Why it's wrong here

    Migration is not required to answer the query, and introducing a second collection adds write and consistency overhead. The Bucket pattern deliberately embeds measurements to reduce document count and index size; abandoning it defeats the design. Aggregation pipelines handle embedded arrays directly, so restructuring the data is unnecessary here.

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.