MongoDB MCQs – Sharding

MongoDB sharding is a method for distributing data across multiple servers to handle large datasets and high throughput operations. It is a key feature for horizontal scaling, allowing MongoDB to support applications with massive data growth. Sharding involves partitioning data into smaller chunks (shards) and distributing them across multiple servers or clusters. Each shard is an independent database, and collectively, they form a single logical database.

These MCQs cover fundamental and advanced concepts of MongoDB sharding, which are frequently tested in technical interviews.

1.) What is sharding in MongoDB?

A) A method for distributing data across multiple servers
B) A method for encrypting data
C) A method for compressing data
D) A method for backing up data

Answer: Option A

Explanation: Sharding is a method for distributing data across multiple servers to handle large datasets and high throughput.

2.) Which component is responsible for routing queries to the correct shard in MongoDB?

A) Shard server
B) Config server
C) Mongos
D) Replica set

Answer: Option C

Explanation: The mongos (MongoDB shard router) is responsible for routing queries to the correct shard.

3.) What is a shard key in MongoDB?

A) A unique identifier for each document
B) A field used to partition data across shards
C) A password for accessing shards
D) A configuration file for sharding

Answer: Option B

Explanation: A shard key is a field used to partition data across shards.

4.) Which of the following is true about a shard in MongoDB?

A) It is a single MongoDB instance
B) It is a query router
C) It is a configuration server
D) It is a replica set or a standalone server

Answer: Option D

Explanation: A shard can be either a replica set or a standalone server that stores a subset of the data.

5.) What is the role of config servers in MongoDB sharding?

A) To store the actual data
B) To act as a backup server
C) To route queries to shards
D) To store metadata and configuration information

Answer: Option D

Explanation: Config servers store metadata and configuration information for the sharded cluster.

6.) Which of the following is true about the shardCollection command?

A) It enables sharding for a database
B) It shards a specific collection
C) It adds a new shard
D) It removes a shard

Answer: Option B

Explanation: The shardCollection command shards a specific collection based on the shard key.

7.) Which command is used to enable sharding for a database in MongoDB?

A) sh.enableSharding()
B) sh.startSharding()
C) sh.initiateSharding()
D) sh.createSharding()

Answer: Option A

Explanation: The sh.enableSharding() command is used to enable sharding for a database.

8.) What is a chunk in MongoDB sharding?

A) A single document
B) A subset of data within a shard
C) A configuration file
D) A query router

Answer: Option B

Explanation: A chunk is a subset of data within a shard, defined by a range of shard key values.

9.) What is the default chunk size in MongoDB?

A) 64 MB
B) 128 MB
C) 256 MB
D) 512 MB

Answer: Option A

Explanation: The default chunk size in MongoDB is 64 MB. This chunk size determines the size of data partitions that MongoDB uses to distribute data across shards in a sharded cluster.

10.) What is the purpose of the sh.moveChunk() command?

A) To merge two chunks
B) To split a chunk
C) To move a chunk from one shard to another
D) To add a new shard

Answer: Option C

Explanation: The sh.moveChunk() command moves a chunk from one shard to another.

Leave a Reply

Your email address will not be published. Required fields are marked *