0
0
MongoDBquery~20 mins

Range-based sharding in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Range Sharding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Find the shard key range for a given document
Given a MongoDB sharded collection with a range-based shard key on the field age, which shard will store the document { "name": "Alice", "age": 25 } if the shard ranges are:

- Shard1: age < 20
- Shard2: 20 ≤ age < 40
- Shard3: age ≥ 40

Choose the correct shard that will contain Alice's document.
AShard2
BShard1
CShard3
DNone of the above
Attempts:
2 left
💡 Hint
Check which range the age 25 falls into.
🧠 Conceptual
intermediate
2:00remaining
Understanding range-based shard key distribution
Why is range-based sharding potentially problematic if the incoming data is mostly increasing in the shard key value?

Choose the best explanation.
AIt evenly distributes writes across all shards.
BIt causes all writes to go to a single shard, leading to unbalanced load.
CIt causes queries to be slower because all shards must be scanned.
DIt prevents any shard from storing data.
Attempts:
2 left
💡 Hint
Think about what happens if new data always has a higher shard key value.
📝 Syntax
advanced
2:00remaining
Identify the correct MongoDB command to enable range-based sharding
Which of the following MongoDB shell commands correctly enables sharding on the users collection using age as the shard key with range-based sharding?
Ash.shardCollection("mydb.users", "age")
Bsh.enableSharding("mydb.users", { age: 1 })
Csh.shardCollection("mydb", { users: { age: 1 } })
Dsh.shardCollection("mydb.users", { age: 1 })
Attempts:
2 left
💡 Hint
The command to shard a collection requires the namespace and shard key as an object.
optimization
advanced
2:00remaining
Optimizing range-based shard key selection
You have a collection where most queries filter by region and timestamp. Which shard key choice will best optimize query performance and data distribution using range-based sharding?
A{ region: 1, timestamp: 1 }
B{ timestamp: 1 }
C{ region: 1 }
D{ _id: 1 }
Attempts:
2 left
💡 Hint
Consider which fields are used in queries and how combining them affects shard distribution.
🔧 Debug
expert
2:00remaining
Diagnose the cause of unbalanced shards in range-based sharding
A MongoDB cluster uses range-based sharding on the orderDate field. Over time, one shard stores 90% of the data, causing performance issues. What is the most likely cause?
AThe shard key is not indexed.
BThe cluster has too many shards configured.
CThe shard key <code>orderDate</code> is monotonically increasing, causing all new inserts to go to one shard.
DThe data is evenly distributed but queries are slow.
Attempts:
2 left
💡 Hint
Think about how range-based sharding handles sequential values.