Courseiva
Sharding →hardMultiple Choice

C100DBA Sharding Practice Question

A MongoDB 6.0 sharded cluster has a collection sharded with a hashed shard key on 'userId'. The operations team needs to run an aggregation that groups documents by 'userId' and calculates the total transaction amount. They want to know whether the aggregation can be optimized to run only on the shards that contain the relevant 'userId' values. Which statement describes the correct behavior?

⚠ Common exam trap

The trap here is thinking that hashed shard keys never allow targeting, when equality queries on the hashed field do target a single shard.

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

✓

The aggregation can target specific shards if the $match stage includes an equality condition on 'userId'.

For a hashed shard key, mongos can target a specific shard when the query includes an equality condition on the shard key field. This is because the hash of the value determines the chunk and thus the shard. Other stages or options do not affect targeting. Therefore, an aggregation with a $match on 'userId' with an equality can be optimized to run on a single shard.

Answer analysis

Option-by-option breakdown

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

  • ✗

    The aggregation can target specific shards only if it includes a $sort stage on 'userId' before the $group stage.

    Why it's wrong here

    The ability to target shards depends on the presence of the shard key in the query predicate, not on the aggregation stages. A $sort on 'userId' does not enable targeting; it may require a merge sort on mongos. Only an equality match on the hashed shard key allows the router to direct the query to a single shard.

  • ✓

    The aggregation can target specific shards if the $match stage includes an equality condition on 'userId'.

    Why this is correct

    With a hashed shard key, an equality match on the shard key field allows mongos to compute the hash and target the specific shard that owns that hashed value. If the aggregation pipeline begins with a $match on 'userId' with an equality condition, the router can direct the operation to a single shard, avoiding scatter-gather.

  • ✗

    The aggregation will always run on all shards because hashed shard keys prevent any query targeting.

    Why it's wrong here

    Hashed shard keys support targeted queries when the query includes an equality condition on the hashed field. The hash function is deterministic, so mongos can compute the target shard for a given value. Range queries cannot be targeted, but equality queries can. Therefore, it is incorrect to say that hashed keys prevent all targeting.

  • ✗

    The aggregation must be run with the allowDiskUse option to target specific shards.

    Why it's wrong here

    The allowDiskUse option allows aggregation stages to write to temporary files when exceeding memory limits, but it has no effect on shard targeting. Targeting is determined by the query predicate on the shard key. Using allowDiskUse does not change the routing behavior and is irrelevant to the question of targeted aggregation.

About these practice questions

One of 222 original C100DBA practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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 C100DBA 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 C100DBA exam.