MongoDB Clusters Shredded Databases Presenter: Abhinav Jha (Software Developer - TMotions Global Pvt. Ltd.)
MongoDB (Journey till now) ● Setting up MongoDB environment. ● Creating Databases, Collections and Documents. ● Document Schema using NF3. ● Creating Queries for manipulating data with Robo 3T.
Latest News ● Latest version: Mongo 4.0 ○ https://docs.mongodb.com/manual/release-notes/4.0/ ● For further news and cool stuffs for mongo ○ https://www.mongodb.com/news
What we will learn today? ● Architecture of sharded cluster. ● Query handling in sharded cluster. ● Data Distribution Method. ● Replica Sets.
What is Replication Replication is a concept of keeping multiple copies of your data. We need replication because you can never assume that all of the servers are always available.
Standalone Vs Replicated Solution Standalone writes data to a single server. Replicated Solution we keep copies of data into different servers.
How it works. ● Binary Replications - strict consistencies along all the servers since it is based on memory index. ● Statement Based Replications - not bound by operating systems or any machine level dependencies.
Setting up replica set Create a config file with the storage, server, port and replica set name.
Connect to Node1:
Important Queries rs.initiate() rs.status() rs.add("<host-name>:<port-number>") rs.isMaster() rs.stepDown() rs.remove("<host-name>:<port-number>")
Arbitrary Node (Only for election) rs.addArb("m103.mongodb.university:28000")
Hidden Node (Stores Backups) cfg = rs.conf() cfg.members[3].votes = 0 cfg.members[3].hidden = true cfg.members[3].priority = 0 rs.reconfig(cfg)
Sharding If the data grows to the limit that our server can't handle the data. We use Sharding
Vertical Sharding ● Add more RAM, Disk Space or processors. ● Very Expensive ● Cloud base does not allow Vertical scaling
Horizontal Scaling ● MongoDB allows horizontal scaling. ● Add more machines. ● Distribute the data set across the machines
Sharded Clusters
Mongos
Setup Shard sharding: clusterRole: configsvr replication: replSetName: aj-replicaset net: bindIp: localhost port: 26001 storage: dbPath: /var/mongodb/db/csrs1
Running mongo instances mongod -f csrs_1.conf mongod -f csrs_2.conf mongod -f csrs_3.conf Connect one of the Server mongo --port 26001
Setup Replica Set rs.initiate() rs.add("192.168.103.100:26002") rs.add("192.168.103.100:26003")
Mongos.cfg sharding: configDB: aj-replicaset/localhost:26001,localhost:26002,localhost:26003 net: bindIp: localhost port: 26000 processManagement: fork: true sh.status() sh.addShard("m103-repl/192.168.103.100:27012")
Update Node Configs sharding: clusterRole: shardsvr storage: dbPath: /var/mongodb/db/node1 wiredTiger: engineConfig: cacheSizeGB: .1 net: bindIp: 192.168.103.100,localhost port: 27011 replication: replSetName: aj-replicaset
References https://docs.mongodb.com/manual/core/sharded-cluster- components/ https://docs.mongodb.com/manual/tutorial/atlas-free-tier- setup/ https://docs.mongodb.com/manual/crud/ https://docs.mongodb.com/manual/replication/
Thanks For Your Time Any Query Please Let Me Know: abhinav.jha@tmotions.com abhinav.jha@haymarket.com

Mongo db cluster administration and Shredded Databases