johlo
johlo

Reputation: 5500

How to determine the MongoDB server type

A MongoDB instance can have different roles:

I know that db.serverStatus() can be used to see if an instance is a router, the process value is mongos. But for config servers, arbiters and data nodes the process value is mongod.

Is there a simple way of distinguishing between these instance types?

Upvotes: 1

Views: 1271

Answers (1)

norberto
norberto

Reputation: 187

I want to bring attention to one particular important issue with this question: sharding is and horizontal dimension ( several replicasets where data is distributed to ) and replicaset is a high availability solution which is represented by the composition of different mongod nodes!

So you actually what you are trying to figure out is:

  • ReplicaSet nodes roles
  • Shard Nodes members

In the case of a replicaSet what you might be interested in knowing is each node role. You can easily get the information without needing to connect to all the nodes of the replicaset, just run the command:

db.isMaster()

with this you will get the node members and roles of each member.

For shard node members first of all you should never try to connect directly to the config servers. These are their to manage the distribution of chunks, chunk splits and other configuration data, relevant only for the shard cluster functionality. Avoid using those ip's to connect to from your application.

So if you want to have a clear view of which members compose your shard cluster, how many shards you have etc, you need to run command:

db.printShardStatus()

or

sh.status()

Please review the documentation here

Cheers, N.

Upvotes: 2

Related Questions