MCQs on Sharding and Scalability | MongoDB MCQs

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?

  1. 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
  2. What type of architecture does sharding implement?
    a) Monolithic
    b) Client-server
    c) Distributed
    d) Peer-to-peer
  3. Which MongoDB component routes queries to the appropriate shard?
    a) Config server
    b) Shard router (mongos)
    c) Replication set
    d) Aggregation pipeline
  4. 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
  5. 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

  1. 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
  2. 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
  3. 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
  4. Which of the following is a common shard key strategy?
    a) Random UUIDs
    b) Range-based keys
    c) Reverse indexing
    d) Config server IDs
  5. 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

  1. 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
  2. What command initializes a sharded cluster?
    a) sh.enableCluster()
    b) sh.shardCollection()
    c) sh.addShard()
    d) sh.startCluster()
  3. How many config servers are recommended for production environments?
    a) 1
    b) 2
    c) 3
    d) 5
  4. Which component is responsible for balancing data between shards?
    a) Config server
    b) Mongos
    c) Replication set
    d) Balancer
  5. 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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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

  1. 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
  2. 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
  3. Which MongoDB command starts a balancer?
    a) sh.startBalancer()
    b) sh.enableBalancer()
    c) sh.restartBalancer()
    d) sh.enableClusterBalancer()
  4. 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
  5. Which type of replication is commonly used in MongoDB?
    a) Master-master replication
    b) Master-slave replication
    c) Replica sets
    d) Eventual consistency
  6. Which operation is impacted by poor shard key selection?
    a) Write operations
    b) Query performance
    c) Data balancing
    d) All of the above
  7. Which component ensures queries are distributed across shards?
    a) Shard balancer
    b) Config server
    c) Mongos
    d) Database driver
  8. Which term describes combining two chunks into one?
    a) Chunk merge
    b) Chunk rebalance
    c) Chunk optimization
    d) Chunk defragmentation
  9. 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
  10. 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

QnoAnswer
1b) Splitting large datasets across multiple servers
2c) Distributed
3b) Shard router (mongos)
4b) Large datasets with high write and read traffic
5c) It eliminates the need for replication
6b) A field used to distribute data across shards
7a) Uniform distribution of data
8b) Data will not be distributed evenly
9b) Range-based keys
10d) All of the above
11b) Storing metadata and mappings for shards
12c) sh.shardCollection()
13c) 3
14d) Balancer
15b) A subset of data in a collection based on the shard key
16b) Data consistency across nodes
17b) Only two of consistency, availability, or partition tolerance can be achieved simultaneously
18d) All of the above
19c) Strongly consistent writes
20b) Replica lag
21b) Adding more servers to distribute data
22c) Large collections with high query throughput
23b) sh.enableBalancer()
24c) The chunk is split into smaller chunks
25c) Replica sets
26d) All of the above
27c) Mongos
28a) Chunk merge
29a) _id field
30b) By replicating chunks across multiple servers

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top