How to do scaling in MongoDB?
There are multiple ways you can scale your site using MongoDB.
1. Horizontal Scaling Syntax:
After choosing the shard keys that evenly distributes data and evaluating the data model, shard according to your needs
"sh.addShard("shard_name/shard_hostname:port") "
This adds shards to distribute data across multiple machines.
To enable sharding use the command:
sh.enableSharding()
To shard a particular collection or dataset use:
sh.shardCollection()
2. Vertical Scaling Syntax
( with MongoDB Atlas):
Go to MongoDB Atlas dashboard.
- Select cluster.
- Click on ‘Modify Cluster’.
- Choose a higher configuration for your cluster (e.g., increase RAM, CPU).
This will upgrade the resources of your existing MongoDB server.
Other methods can be
- Upgrading hardware.
- Cloud providers like AWS(Amazon Web Services), Azure.
- Database optimization.
- Distributed computers.
Horizontal Vs Vertical Scaling in MongoDB
Horizontal and vertical scaling are two common strategies used to handle increasing loads or data volumes in databases like MongoDB. MongoDB is a popular open-source, NoSQL database management system that uses a document-oriented data model. It has multiple features like high performance, flexibility, and scalability. In this article, we will talk about its scalability aspect.
Table of Content
- What is scalability?
- Horizontal Scaling
- Vertical Scaling
- Use Cases
- Which one to choose?
- How to do scaling in MongoDB?
- Difference between of Horizontal and Vertical Scrolling
Contact Us