0
0
MongoDBquery~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hash Sharding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of Hash-based Sharding on Query Routing

Consider a MongoDB collection sharded by hashing the user_id field. Which statement best describes how queries with a specific user_id value are routed?

AThe query is routed to all shards because hashed keys are distributed randomly.
BThe query is routed only to the shard that contains the hashed <code>user_id</code> value.
CThe query is routed to the primary shard regardless of the <code>user_id</code> value.
DThe query is routed to shards based on the range of <code>user_id</code> values.
Attempts:
2 left
💡 Hint

Think about how hashing distributes data evenly and how MongoDB uses the hash to locate data.

🧠 Conceptual
intermediate
2:00remaining
Why Use Hash-based Sharding?

What is the main advantage of using hash-based sharding in MongoDB compared to range-based sharding?

AIt allows for efficient range queries on the shard key.
BIt stores data in sorted order on each shard.
CIt evenly distributes data and load across all shards regardless of key distribution.
DIt automatically replicates data to all shards.
Attempts:
2 left
💡 Hint

Consider how data distribution affects load balancing.

📝 Syntax
advanced
2:00remaining
Correct Syntax to Enable Hash-based Sharding

Which MongoDB command correctly enables sharding on the users collection using a hashed user_id shard key?

Ash.shardCollection('mydb.users', { user_id: 'hashed' })
Bsh.shardCollection('mydb.users', { user_id: 'hash' })
Csh.shardCollection('mydb.users', { user_id: 'hashedKey' })
Dsh.shardCollection('mydb.users', { user_id: 'hashing' })
Attempts:
2 left
💡 Hint

Check the exact keyword MongoDB expects for hashed shard keys.

optimization
advanced
2:00remaining
Optimizing Query Performance with Hash-based Sharding

You have a MongoDB collection sharded by hashing email. Which practice will improve query performance for lookups by email?

AAvoid indexing the <code>email</code> field to reduce overhead.
BCreate a compound shard key with <code>email</code> and <code>signup_date</code>.
CUse range queries on <code>email</code> to leverage shard key ordering.
DAlways include the <code>email</code> field in queries to enable targeted shard routing.
Attempts:
2 left
💡 Hint

Think about how MongoDB routes queries in hash-based sharding.

🔧 Debug
expert
3:00remaining
Diagnosing Uneven Data Distribution in Hash-based Sharding

A MongoDB collection is sharded by hashing customer_id. However, one shard stores 80% of the data, causing performance issues. What is the most likely cause?

AThe balancer is disabled, preventing data from moving to balance shards.
BThe shard key is not actually hashed, but used as a range shard key by mistake.
CThe hash function is not distributing values evenly due to a small shard key value range.
DThe <code>customer_id</code> values are not unique, causing data duplication on one shard.
Attempts:
2 left
💡 Hint

Consider what controls data movement between shards after initial distribution.