Range-based Sharding in MongoDB
📖 Scenario: You are managing a large online bookstore database. To handle the growing number of book sales efficiently, you want to distribute the sales data across multiple servers based on the sale date. This technique is called range-based sharding.Range-based sharding splits data into chunks based on a range of shard key values. Here, the shard key will be the saleDate field.
🎯 Goal: Set up a MongoDB sharded collection called bookSales in the bookstore database. Configure range-based sharding on the saleDate field to distribute sales data by date ranges.
📋 What You'll Learn
Create the
bookSales collection with sample sales documents.Enable sharding on the
bookstore database.Shard the
bookSales collection using saleDate as the shard key.Split the data into at least two chunks based on
saleDate ranges.💡 Why This Matters
🌍 Real World
Range-based sharding helps large databases distribute data efficiently by ranges, improving query performance and scalability.
💼 Career
Database administrators and backend engineers use sharding to manage big data and ensure fast access in production systems.
Progress0 / 4 steps