Tuesday, September 11, 2018

Basic MongoDB queries

 1) For config servers listing:

Connect to mongos

> use admin

> db.runCommand("getShardMap")


2) For listing shards and its replica sets:

Connect to mongos

> use admin

> db.adminCommand({ listShards: 1 })


3) For Knowing primary and secondary preference:

Connect to mongodb

>rs.conf()

Under members array, priority 0 -1000 defines the nodes priority to become Primary, higher the number higher chance of getting primary.

If priority is 0, then that node will never become primary.

For changing the priority, https://docs.mongodb.com/manual/tutorial/adjust-replica-set-member-priority/

Important: Arbiters are mongod instances that are part of replica set but do not hold data, Arbiters participate in elections in order to break ties. If a replica set has an even number of members, add an arbiter.

Arbiters participate in elections in order to break ties. If a replica set has an even number of members, add an arbiter.

Type: Number between 0 and 1000 for primary/secondary; 0 or 1 for arbiters.


***