Posts

MongoDB

Mongodb is a document based NOSQL database.

Comparison with RDBMS 

Here , 

  • Collection is Table
  • Database is Database
  • Document(JSON) is Record/Row stored as binary which is BSON

BSON  


Wired Tiger Engine is the storage engine in mongodb 
Stores document in the form of BSON which stands for Binary JSON
Mongodb uses B-Tree algorithm internally
Indexing required for better query performance

Documents are schema less i.e. we can add info to any objects in single collection unlike RDBMS in which adds column by altering schema structure.


Mongodb Architecture

In the context of MongoDB, “cluster” is the word usually used for either a replica set or a sharded cluster

Mongos : The instances provide the interface between the client applications and the sharded cluster

Config servers :  Stores the meta data for a sharded cluster

Client : Connects mongo server through the drivers

Replication sets:

8

Replica type  : Master-Slave

Heartbeat happens for every 10sec between the replicas and if the machine is down, one of the nodes is elected as primary. Once the failover server is up it will be acting as secondary.. and waits for other failovers.

We can read and write on primary server which is elected among the sets

Writing on primary will enter in Oplog and secondary servers replicates from Oplog



Write operation must go only on primary node while read operation can go either primary or  secondary nodes for load balancing

Setup : Install three nodes, create replica in each node and initiate replication on any one node


Sharding


Multiple replica sets forms a Sharded cluster for horizontal scaling. 

It is a method for distributing data across multiple machines

Sharding is based on collection 


Each shard has a set of value and split across the other shards,

For example Shard 1 has 1-100, Shard2 has 100-200 and so on... 

Start mongodb now.. click here

Configuring Sharded cluster

  • Start config servers replicaset
  • Start shard servers replicasets
  • Start mongos instance by configuring the config servers replicaset
  • Add shards in mongos instance
  • We don't shard a database We shard a collection*
  • Enable sharding databse before using the database in sharding

Config servers version update :
Starting in version 3.4, the use of the deprecated mirrored mongod instances as config servers (SCCC) is no longer supported. Before you can upgrade your sharded clusters to 3.4, you must convert your config servers from SCCC to CSRS.

Comments