Sample questions
Question 1Easy
Which stage groups documents and computes totals?
- $group
- $sum
- $count_by
- $bucketize
Answer: A. $group
Explanation
$group groups by an _id expression and can use accumulators like $sum and $avg.
Step-by-step solution
- Pick the stage that groups.
- Use accumulators inside it.
Why the other options are wrong
- B. $sum is an accumulator used inside $group.
- C. There is no $count_by stage; $group does the aggregation.
- D. $bucket splits values into ranges; it does not compute totals per group.
Question 2Easy
Which stage skips the first n documents?
- $jump
- $offset
- $drop
- $skip
Answer: D. $skip
Explanation
$skip drops n documents from the stream.
Step-by-step solution
- Name it.
Why the other options are wrong
- A. There is no $jump stage; $skip skips documents.
- B. There is no $offset stage; $skip skips documents.
- C. There is no $drop stage; $skip skips documents.
Question 3Easy
Which MongoDB method runs a multi-stage data processing pipeline?
- pipeline()
- aggregate()
- reduceAll()
- group()
Answer: B. aggregate()
Explanation
aggregate() takes an array of stages.
Step-by-step solution
- The
aggregate() method is used for multi-stage data processing in MongoDB. - It accepts an array of pipeline stages as input.
- Each stage performs a specific operation on the data stream.
- This allows complex data transformations across multiple steps.
- The correct answer is aggregate().
Why the other options are wrong
- A. pipeline is not a MongoDB method; the multi-stage method is aggregate.
- C. reduceAll is not a MongoDB method for running stages.
- D. group is a stage inside a pipeline, not the method that runs the pipeline.
Tip: Use aggregate() for complex data pipelines with multiple stages.
Question 4Easy
Which stage filters documents in an aggregation pipeline?
- $filter
- $where
- $select
- $match
Answer: D. $match
Explanation
$match keeps only documents satisfying the conditions, like find's filter.
Step-by-step solution
- Filtering stage name.
- $match.
Why the other options are wrong
- A. $filter is an array expression operator.
- B. $where is a JavaScript query operator.
- C. There is no $select stage; $match is the filtering stage.
Tip: Put $match early to reduce work.
Question 5Medium
What does this pipeline compute?
db.orders.aggregate([
{$group: {_id: '$city', total: {$sum: '$amount'}}}
])
- The number of orders per city
- Total order amount per city
- The average amount per city
- The largest order overall
Answer: B. Total order amount per city
Explanation
$sum on a field adds that field across each group.
Step-by-step solution
- Group by city.
- Sum the amount field.
Why the other options are wrong
- A. Counting would be {$sum: 1}.
- C. Average would use $avg.
- D. No maximum is taken; the pipeline sums amounts per city.
Tip: $sum: 1 counts documents.
Question 6Medium
Which stage counts the documents reaching it into a named field?
- {$total: 'n'}
- {$sumAll: 'n'}
- {$count: 'n'}
- {$size: 'n'}
Answer: C. {$count: 'n'}
Explanation
$count outputs one document with the count in the given field.
Step-by-step solution
- Stage with a field name.
Why the other options are wrong
- A. There is no $total stage; $count is the counting stage.
- B. There is no $sumAll stage; $count is the counting stage.
- D. $size is an array operator.
Question 7Medium
What does $sort: {total: -1} followed by $limit: 3 compute?
- Bottom 3 by total
- Top 3 by total
- First 3 in insertion order
- Random 3
Answer: B. Top 3 by total
Explanation
Sort descending then keep three.
Step-by-step solution
- -1 is descending.
- Limit 3.
Why the other options are wrong
- A. Ascending would give the bottom.
- C. Sorting then limiting orders by total, not by insertion order.
- D. Order is deterministic.
Question 8Medium
What does $project do in a pipeline?
- Filters out the documents that fail a given condition, as $match does
- Sorts the documents by a chosen key
- Reshapes documents by including, excluding or computing fields
- Writes the documents to another collection
Answer: C. Reshapes documents by including, excluding or computing fields
Explanation
$project selects and transforms fields.
Step-by-step solution
- It acts on fields, not rows.
Why the other options are wrong
- A. $project reshapes fields; it does not remove documents.
- B. Sorting is done by $sort, not by $project.
- D. Writing to a collection is $out or $merge, not $project.
Question 9Hard
- Faceted full-text search over a single text index only
- Joining two collections by a shared key field
- Running several sub-pipelines on the same input in one stage
- Creating indexes for each sub-pipeline automatically
Answer: C. Running several sub-pipelines on the same input in one stage
Explanation
$facet outputs multiple result arrays from parallel sub-pipelines.
Step-by-step solution
- One input, several outputs.
Why the other options are wrong
- A. $facet runs sub-pipelines on one input; it is not text search.
- B. $facet does not join collections; $lookup handles joins.
- D. $facet does not create indexes for its sub-pipelines.
Question 10Hard
What does {$group: {_id: null, avg: {$avg: '$mark'}}} return?
- One document per distinct mark value in the input
- One document with the average of mark across all input documents
- Nothing, because _id cannot be null in a $group stage
- The median mark
Answer: B. One document with the average of mark across all input documents
Explanation
A constant (null) _id puts all documents into one group.
Step-by-step solution
- _id null means a single group.
- $avg computes the mean.
Why the other options are wrong
- A. Groups by null, not per mark.
- C. A null _id in $group is valid and groups all documents together.
- D. $avg returns the mean, not the median.
Practise all 24 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →