Courseiva
Aggregation Framework →mediumMultiple Choice

C100DEV Aggregation Framework Practice Question

What is the purpose of the $accumulator stage in the aggregation framework?

⚠ Common exam trap

Candidates often assume $accumulator is a native performance-optimized operator, failing to account for the overhead of executing custom JavaScript code, which can significantly slow down large-scale data processing.

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

✓

To define custom aggregation logic.

The $accumulator stage allows developers to define custom aggregation logic using JavaScript functions. This is useful for scenarios where built-in accumulators like $sum or $avg are insufficient, such as calculating complex statistical models or performing custom data parsing that requires state maintenance during the grouping process. Because it executes JavaScript, it should be used judiciously, as it can be slower than native pipeline operators.

Answer analysis

Option-by-option breakdown

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

  • ✗

    To replace $group.

    Why it's wrong here

    The $accumulator stage is an operator used within the $group stage, not a standalone replacement for $group itself. It provides the logic for the accumulation process, while the $group stage provides the framework for organizing the input documents into buckets based on a key.

  • ✓

    To define custom aggregation logic.

    Why this is correct

    $accumulator allows for complex, user-defined logic that goes beyond standard operators. By providing an init, accumulate, and merge function, you gain full control over how documents are processed and aggregated, enabling custom calculations that are not supported by standard MongoDB aggregation operators.

  • ✗

    To improve performance over native operators.

    Why it's wrong here

    $accumulator is actually slower than native operators because it involves executing JavaScript within the aggregation engine. Native operators are implemented in C++ and are highly optimized; therefore, custom JavaScript code will almost always have higher latency and resource consumption than native-equivalent operations.

  • ✗

    To perform joins across collections.

    Why it's wrong here

    $accumulator is for aggregation logic, not for data correlation or joining. The $lookup stage is dedicated to joining data between collections. Mixing these two concepts is incorrect, as $accumulator operates on the data within a single document stream during grouping, not across separate collections.

About these practice questions

Courseiva writes every C100DEV question from scratch — 259 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.