</>
Skip to content
MongoDB lessons (35/38)

MongoDB — Sharding

What is Sharding?

Sharding distributes data across multiple machines.

Components

ComponentDescription
ShardStores data
ConfigMetadata
RouterQuery routing

Enable Sharding

// Enable on database
sh.enableSharding("mydb")

// Shard collection
sh.shardCollection("mydb.users", { userId: "hashed" })

Shard Key

TypeDescription
HashedEven distribution
RangedRange-based

Check Status

sh.status()

Mini Practice

  1. Enable sharding
  2. Choose shard key
  3. Check shard status
  4. Monitor performance

Up Next

Continue with Atlas — MongoDB Atlas cloud service.

Related Topics

Frequently Asked Questions about Sharding

What is Sharding in MongoDB?

Sharding is a fundamental concept in MongoDB. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Sharding?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Sharding.

Why is Sharding important in MongoDB?

Sharding is essential for MongoDB development. Understanding this concept will help you write better code and solve real-world problems more effectively.