0
0
MongoDBquery~5 mins

Shard key selection importance in MongoDB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a shard key in MongoDB?
A shard key is a field or set of fields that determines how data is distributed across different shards in a MongoDB cluster. It helps split the data into chunks for efficient storage and retrieval.
Click to reveal answer
beginner
Why is choosing the right shard key important?
Choosing the right shard key is important because it affects how evenly data and workload are distributed across shards. A good shard key improves performance and scalability, while a bad one can cause bottlenecks and uneven load.
Click to reveal answer
intermediate
What happens if the shard key causes data to be unevenly distributed?
If the shard key causes uneven data distribution, some shards get overloaded while others stay underused. This leads to slower queries and can reduce the cluster's overall efficiency.
Click to reveal answer
intermediate
How does a shard key affect query performance?
A shard key that matches query patterns allows MongoDB to target specific shards, making queries faster. If the shard key is not used in queries, MongoDB must search all shards, slowing down performance.
Click to reveal answer
advanced
Can the shard key be changed after sharding a collection?
No, MongoDB does not allow changing the shard key after sharding a collection. To change it, you must create a new sharded collection with the desired shard key and migrate data.
Click to reveal answer
What is the main role of a shard key in MongoDB?
ATo create indexes on all fields
BTo encrypt data in the database
CTo backup data automatically
DTo split data across shards evenly
What is a consequence of choosing a poor shard key?
AQueries run faster
BSome shards become overloaded
CData is evenly distributed
DShard key can be changed easily
Which query pattern benefits most from a good shard key?
AQueries that use the shard key fields
BQueries that scan all shards
CQueries that do not use the shard key
DQueries that only update indexes
Can you change the shard key of a collection after sharding it?
ANo, you must create a new collection
BYes, anytime easily
CYes, but only with admin rights
DOnly if the collection is empty
Which of these is a good characteristic of a shard key?
AHas low cardinality (few unique values)
BIs never used in queries
CHas high cardinality (many unique values)
DIs a large text field
Explain why selecting the right shard key is crucial for MongoDB performance and scalability.
Think about how data and queries spread across servers.
You got /4 concepts.
    Describe what happens if a shard key causes uneven data distribution and how it affects the cluster.
    Imagine some servers working too hard while others are idle.
    You got /4 concepts.