Professional Documents
Culture Documents
20mia1061 (Yash Nair) - Nosql Da - 1
20mia1061 (Yash Nair) - Nosql Da - 1
Dataset Used :
https://www.kaggle.com/datasets/bravehart101/sample-supermarket-dataset
Replication Set :
use admin
switched to db admin
db.adminCommand({shutdown:1,comment:"Convert to cluster"})
db.adminCommand({replSetGetStatus:1})
MongoDB Compass :
Step 3: Initiate the Replication.
rs.initiate()
rs.add("localhost:27027")
rs.add("localhost:27037")
rs.status()
Step 6: Create a database and insert a record in the collection.
show dbs
use truly
db.users.insert({"name":"Hello"})
db.users.find()
Step 7: Import the CSV file via Compass. Since it’s a replication set, all three
sets will have the same data stored i.e. 10.0k documents in 27017, 27027, and
27037 ports.
MongoDB Sharding
Step 6: Start the mongos service at 26061 and add the shards, a and b.
use mydb
sh.enableSharding(“mydb”)
Step 8: Shard the collection test1 using the shardkey “runtime” as hashed.
sh.shardCollection(“mydb.test1”,{“runtime”:”hashed”})
Step 9: Import the csv file in the collection test1 in mydb database
If we take a look at the Compass for all different ports,
● 26061 - Config server having all the 10.0k documents