MongoDB’s sharding capability is vital for achieving scalability in distributed systems. Sharding splits large datasets across multiple servers to ensure optimal performance and storage management. This guide covers the fundamentals of sharding, shard key selection, shard configuration, and challenges in distributed systems. Master these concepts to design high-performing MongoDB solutions.
What is Sharding?
What is the primary purpose of sharding in MongoDB? a) Encrypting data across nodes b) Splitting large datasets across multiple servers c) Backing up database systems d) Indexing collections
What type of architecture does sharding implement? a) Monolithic b) Client-server c) Distributed d) Peer-to-peer
Which MongoDB component routes queries to the appropriate shard? a) Config server b) Shard router (mongos) c) Replication set d) Aggregation pipeline
What kind of data is best suited for sharding in MongoDB? a) Small static datasets b) Large datasets with high write and read traffic c) Encrypted data files d) Backups of databases
Which of the following is NOT true about sharding? a) It increases storage capacity b) It improves query performance c) It eliminates the need for replication d) It allows horizontal scaling
Choosing a Shard Key
What is a shard key in MongoDB? a) A primary key for collections b) A field used to distribute data across shards c) A configuration file for shards d) An index for faster queries
Which characteristic is essential for a good shard key? a) Uniform distribution of data b) Small document size c) High query complexity d) Minimal indexing
What happens if the shard key is not chosen carefully? a) Queries will always fail b) Data will not be distributed evenly c) Indexing becomes impossible d) Sharding is disabled
Which of the following is a common shard key strategy? a) Random UUIDs b) Range-based keys c) Reverse indexing d) Config server IDs
Which operation cannot be performed on an existing shard key? a) Renaming it b) Updating its values c) Changing its data type d) All of the above
Configuring and Managing Shards
What is the role of a config server in a sharded cluster? a) Managing shard nodes b) Storing metadata and mappings for shards c) Executing queries across shards d) Handling replication tasks
What command initializes a sharded cluster? a) sh.enableCluster() b) sh.shardCollection() c) sh.addShard() d) sh.startCluster()
How many config servers are recommended for production environments? a) 1 b) 2 c) 3 d) 5
Which component is responsible for balancing data between shards? a) Config server b) Mongos c) Replication set d) Balancer
What is a chunk in a sharded cluster? a) A copy of the entire database b) A subset of data in a collection based on the shard key c) An unsharded portion of data d) A replication log
Challenges in Distributed Systems
Which issue is commonly faced in distributed databases like MongoDB? a) Single-point failures b) Data consistency across nodes c) Limited scalability d) Lack of backups
What does the CAP theorem state? a) A database can prioritize all three: consistency, availability, and partition tolerance b) Only two of consistency, availability, or partition tolerance can be achieved simultaneously c) Sharding requires a consistent shard key d) Partition tolerance is not necessary in distributed systems
What challenge arises due to network partitioning in distributed systems? a) Increased latency b) Data replication failures c) Loss of transaction consistency d) All of the above
Which method ensures write consistency in distributed systems? a) Multi-version concurrency control (MVCC) b) Write-ahead logging c) Strongly consistent writes d) Causal consistency
Which term refers to the delay in data being synchronized across shards? a) Shard delay b) Replica lag c) Latency window d) Data inconsistency
Mixed Questions
What is horizontal scaling in MongoDB? a) Adding more CPUs to a single server b) Adding more servers to distribute data c) Increasing database indices d) Compressing data files
Which scenario is ideal for MongoDB sharding? a) A collection with frequent small reads and writes b) A dataset that fits in a single server c) Large collections with high query throughput d) Low-traffic databases
Which MongoDB command starts a balancer? a) sh.startBalancer() b) sh.enableBalancer() c) sh.restartBalancer() d) sh.enableClusterBalancer()
What happens when a chunk exceeds the configured size? a) The chunk is ignored b) The cluster stops accepting queries c) The chunk is split into smaller chunks d) All data in the chunk is replicated
Which type of replication is commonly used in MongoDB? a) Master-master replication b) Master-slave replication c) Replica sets d) Eventual consistency
Which operation is impacted by poor shard key selection? a) Write operations b) Query performance c) Data balancing d) All of the above
Which component ensures queries are distributed across shards? a) Shard balancer b) Config server c) Mongos d) Database driver
Which term describes combining two chunks into one? a) Chunk merge b) Chunk rebalance c) Chunk optimization d) Chunk defragmentation
What is the default shard key selection if not explicitly set? a) _id field b) First indexed field c) Random field d) No shard key is used
How does MongoDB ensure fault tolerance in sharded clusters? a) Through data encryption b) By replicating chunks across multiple servers c) By disabling the balancer d) By using a single config server
Answer Key
Qno
Answer
1
b) Splitting large datasets across multiple servers
2
c) Distributed
3
b) Shard router (mongos)
4
b) Large datasets with high write and read traffic
5
c) It eliminates the need for replication
6
b) A field used to distribute data across shards
7
a) Uniform distribution of data
8
b) Data will not be distributed evenly
9
b) Range-based keys
10
d) All of the above
11
b) Storing metadata and mappings for shards
12
c) sh.shardCollection()
13
c) 3
14
d) Balancer
15
b) A subset of data in a collection based on the shard key
16
b) Data consistency across nodes
17
b) Only two of consistency, availability, or partition tolerance can be achieved simultaneously