MongoDB MongoDB Replication and Sharding 2 — Questions and Answers
Question 1: What is horizontal scaling in MongoDB achieved through?
- Adding more CPU and RAM to existing servers
- Sharding data across multiple servers (Correct answer)
- Adding more replica set members
- Using faster NVMe storage
Correct answer: Sharding data across multiple servers
Sharding distributes data across multiple machines (shards), allowing MongoDB to handle datasets and throughput that exceed single-server capacity.
Question 2: What is a shard key in MongoDB sharding?
- An encryption key for shard data
- The field(s) used to partition documents across shards (Correct answer)
- A unique identifier for each shard server
- A key that unlocks a shard for maintenance
Correct answer: The field(s) used to partition documents across shards
The shard key determines how documents are distributed across shards; choosing a good shard key is critical for even data distribution and query efficiency.
Question 3: What is a mongos in a MongoDB sharded cluster?
- A monitoring service for shard health
- A query router that directs client requests to the appropriate shard(s) (Correct answer)
- The primary shard for system collections
- A shard configuration backup service
Correct answer: A query router that directs client requests to the appropriate shard(s)
mongos is a routing service that acts as an interface between the client and the sharded cluster, directing queries and writes to the correct shard(s).
Question 4: What stores cluster metadata in a MongoDB sharded cluster?
- The primary shard
- mongos instances
- Config servers (a separate replica set) (Correct answer)
- The admin database on each shard
Correct answer: Config servers (a separate replica set)
Config servers form a dedicated replica set that stores the cluster's metadata, including chunk ranges and shard locations.
Question 5: What is a chunk in MongoDB sharding?
- A 64MB block of data on disk
- A contiguous range of shard key values that MongoDB migrates as a unit (Correct answer)
- A batch of documents processed together
- A compressed segment of collection data
Correct answer: A contiguous range of shard key values that MongoDB migrates as a unit
Chunks are contiguous ranges of shard key values; MongoDB automatically splits and migrates chunks to balance data across shards.
Question 6: What is a targeted query in a sharded MongoDB cluster?
- A query with specific performance targets set
- A query that includes the shard key, allowing mongos to route it to specific shard(s) (Correct answer)
- A query using targeted indexes only
- A query from an authorized administrative account
Correct answer: A query that includes the shard key, allowing mongos to route it to specific shard(s)
A targeted query includes the shard key in its filter, enabling mongos to route it to only the relevant shard(s) rather than broadcasting to all shards.
What is horizontal scaling in MongoDB achieved through?