SQL Essentials Training & Certification
- 7k Enrolled Learners
- Self Paced
One can directly connect to Mongod either using the application driver or Mongo client. Other option is the cluster that has to be built. Mongod can work as a single node of the cluster. In that case, one can connect the Mongod from your Mongos and it will act between the app driver or Mongo client or Mongod.
From the application driver or Mongo client, one can connect to Mongos, and Mongos will connect internally to the Mongod. In the development environment, there is only one node. If there are multiple nodes from the application driver, connecting to multiple nodes is not required. You have to connect only to Mongos and they will connect to multiple nodes and collect the data. For that Mongos takes the help of a configuration database which is called Configdb. Mongos is a query router which acts between the Mongo and Mongod cluster. Config database actually contains the meta data which is kept in the cluster or node.
In the above image, one node is a shard cluster. There are multiple clusters, where Mongos is one of the interface and it acts as a query router. From the application driver or from the Mongo client, instead of connecting to multiple nodes, connect to the Mongos and they will do the query distribution. Mongos takes help of the configuration database and contains the Meta data of this cluster.
In the productions scenario,there are multiple Mongos and above the Mongos there is generally a load balancer. It’s either a HTDP load balancer or a hardware load balancer, so it has a client affinity to connect all the Mongos. From your application driver you connect to multiple Mongos using that load balancer. All the different Mongos work similarly.
Replication works inside the boxes in the image. For instance, inside the shard 1 column, there is a configured replication mechanism and this box contains 256 GB data. It is called the primary member of this shard. The other two members are called as secondary. A shard is not a single Mongod process, but it should be a combo of Mongod process which is a replica set.
Got a question for us? Mention them in the comments section and we will get back to you.