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.
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
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
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
No, the shard key cannot be changed after a collection is sharded.
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