MongoDB - Sharding - Interview Questions

What is sharding. How does MongoDB perform sharding?

 

Sharding is a method of distributing data across multiple machines. MongoDB supports horizontal scaling by Sharding. MongoDB supports deployments with large data sets and high throughput operations via Sharding.

What are the components of a MongoDB sharded cluster?

 

A MongoDB sharded cluster contains following three components.

1. Shard: Shard contains a subset of the sharded data. Each shard can be deployed as a replica set

2. Mongos: Mongos provide an interface between the client applications and the mongo cluster. Mongos act as a query router to the sharded cluster.

3. Config servers: Config servers store metadata and configuration settings for the MongoDB sharded cluster

What are the components of a MongoDB sharded cluster?

 

A MongoDB sharded cluster contains following three components.

1. Shard: Shard contains a subset of the sharded data. Each shard can be deployed as a replica set

2. Mongos: Mongos provide an interface between the client applications and the mongo cluster. Mongos act as a query router to the sharded cluster.

3. Config servers: Config servers store metadata and configuration settings for the MongoDB sharded cluster

What is a shard key?

 

Shard key is used by MongoDB to distribute the documents of a collection across shards. Shard key consists of a field or fields that exist in every document of the MongoDb collection

Can you change the shard key after a collection is sharded?

 

No, the shard key cannot be changed after a collection is sharded.

What are the advantages of sharding?

 

Following are the key advantages of sharding a MongoDB collection.

1. Faster reads: Queries that include a shard key or a prefix of a compound shard key are faster, because MongoDB can target the search to a specific shard.

2. Horizontal scaling: Both read and write loads can be scaled horizontally by adding more shards to the cluster.

3. Storage capacity: Storage capacity of the cluster can be increased by increasing the number of shards. in the cluster

4. High availability: Sharding increases the availability of requests since the sharded cluster can continue to perform read and write operations even if one of the shards is unavailable

 
Important Keywords to Remember

Subscribe to our Questions

Ad
EARN SIDE INCOME

Earn income using your skills and hobbies that you are passioniate about.

Earn Side Income with Photos
Earn Side Income with Writing
Ad
FINANCIAL INDEPENDENCE

Transition out of you full-time job by creating businesses that you are passioniate about.