• Articles
  • Tutorials
  • Interview Questions

Sharding

What is Sharding?

Database Sharding is considered to be the horizontal partitioning of a database or the search engine where each partition is called as a Shard. This is a process of compressing the data collections by splitting the database instances across multiple databases. This in turn fastens the speed of MongoDB CRUD operations. MongoDB creates Shard keys which distribute the data across multiple shards.

sharding

Purpose of database sharding

Due to following reasons database sharding holds an important place in MongoDB –

  • Scaling out to multiple nodes
  • Easy to add new machines
  • Automatic balance of load
  • Zero downtime
  • Automatic failure recovery

Big data

Process of creating database shard

Follow the given steps to create a database shard-

  1. Create a batch file with the name bat at the root of MongoDB’s bin folder.
  2. Write following lines on the batch file:

mkdir“data/localhost10000”

mongod –rest –shardsvr –port 10000 –dbpath data/localhost10000 –logpath data/localhost10000/log.txt
PAUSE

  1. Create another batch file with the name bat at the root of MongoDB’s bin folder.
  2. Write following lines on the batch file:

mkdir “data/localhost10001”
mongod –rest –shardsvr –port 10001 –dbpath data/localhost10001 –logpath data/localhost10001/log.txt
PAUSE

  1. Run RunServer10000.bat
  2. Run RunServer10001.bat

 

Course Schedule

Name Date Details
MongoDB Training 23 Nov 2024(Sat-Sun) Weekend Batch View Details
30 Nov 2024(Sat-Sun) Weekend Batch
07 Dec 2024(Sat-Sun) Weekend Batch

About the Author

Data Engineer

As a skilled Data Engineer, Sahil excels in SQL, NoSQL databases, Business Intelligence, and database management. He has contributed immensely to projects at companies like Bajaj and Tata. With a strong expertise in data engineering, he has architected numerous solutions for data pipelines, analytics, and software integration, driving insights and innovation.