Courseiva
Sharding →mediumMultiple Choice

C100DBA Sharding Practice Question

A sharded cluster has a collection sharded on `{ location: 1 }`. A query is executed with the filter `{ location: { $in: ["NY", "CA"] } }`. How does MongoDB route this query?

⚠ Common exam trap

The trap here is assuming that `$in` queries cannot be targeted, when in fact mongos can route them to specific shards based on the shard key values.

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 query is routed to the shards that own chunks covering the values "NY" and "CA".

MongoDB's query router, mongos, can target queries that include the shard key, even with `$in`. It looks up the chunk ranges for the specified values and routes the query only to the shards that own those chunks. This is known as a targeted query and is efficient because it avoids contacting unnecessary shards.

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 query is sent to all shards because `$in` cannot be targeted.

    Why it's wrong here

    MongoDB can target queries with `$in` on the shard key if the values are known. The query router (mongos) can determine which chunks contain the specified values and route the query only to the shards hosting those chunks. It does not need to broadcast to all shards.

  • ✗

    The query is routed to a random shard, and that shard forwards the request to the others as needed.

    Why it's wrong here

    MongoDB does not route queries to a random shard for forwarding. The mongos router uses the shard key to determine the target shards. If the query cannot be targeted, it broadcasts to all shards. A random shard would not forward the request; that is not how sharded clusters operate.

  • ✗

    The query is routed to the primary shard for the database because `$in` is not a targeted operation.

    Why it's wrong here

    There is no concept of a primary shard for a database for query routing. The primary shard is where unsharded collections reside, but for sharded collections, queries are routed based on the shard key. The `$in` operator on the shard key allows targeting specific shards, not the primary shard.

  • ✓

    The query is routed to the shards that own chunks covering the values "NY" and "CA".

    Why this is correct

    When a query includes the shard key with `$in`, mongos can identify the specific chunks that contain those values and route the query only to the shards hosting those chunks. This is a targeted query, which minimizes the number of shards contacted and improves performance.

About these practice questions

Courseiva writes every C100DBA question from scratch — 222 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 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.