MongoDB
Mongodb Primary Key: Example to set _id field with ObjectId()
What is Primary Key in MongoDB? In MongoDB, _id field as the primary key for the collection so...
Sharding is a concept in MongoDB, which splits large data sets into small data sets across multiple MongoDB instances.
Sometimes the data within MongoDB will be so huge, that queries against such big data sets can cause a lot of CPU utilization on the server. To tackle this situation, MongoDB has a concept of Sharding, which is basically the splitting of data sets across multiple MongoDB instances.
The collection which could be large in size is actually split across multiple collections or Shards as they are called. Logically all the shards work as one collection.
Shards are implemented by using clusters which are nothing but a group of MongoDB instances.
The components of a Shard include
Step 1) Create a separate database for the config server.
mkdir /data/configdb
Step 2) Start the mongodb instance in configuration mode. Suppose if we have a server named Server D which would be our configuration server, we would need to run the below command to configure the server as a configuration server.
mongod –configdb ServerD: 27019
Step 3) Start the mongos instance by specifying the configuration server
mongos –configdb ServerD: 27019
Step 4) From the mongo shell connect to the mongo's instance
mongo –host ServerD –port 27017
Step 5) If you have Server A and Server B which needs to be added to the cluster, issue the below commands
sh.addShard("ServerA:27017") sh.addShard("ServerB:27017")
Step 6) Enable sharding for the database. So if we need to shard the Employeedb database, issue the below command
sh.enableSharding(Employeedb)
Step 7) Enable sharding for the collection. So if we need to shard the Employee collection, issue the below command
Sh.shardCollection("db.Employee" , { "Employeeid" : 1 , "EmployeeName" : 1})
Summary:
What is Primary Key in MongoDB? In MongoDB, _id field as the primary key for the collection so...
You do not need install the MongoDB server and configure it. You can deploy MongoDB Atlas server...
While authorization looks at ensuring the client access to the system, the authentication checks...
In MongoDB, the first basic step is to have a database and collection in place. The database is...
{loadposition top-ads-automation-testing-tools} MongoDB is an open source NoSQL DBMS which uses a...
What is MongoDB? MongoDB is a document-oriented NoSQL database used for high-volume data storage....