3

I need a simple check for identifying that I am connected to a MongoDB config server.

I can check the process to differentiate between mongod and mongos:

> db.serverStatus().process;
mongod

Now I make an assumption that config server is the one without a replica set name, but it would not always hold true. I check that below returns a NULL value.

> db.serverStatus().repl.setName;

What is a better way to identify config server from mongod in a simple manner? This would be useful for custom prompt function based on the connection.

3

I found one way to do it.

On config server:

> db.serverCmdLineOpts().parsed.sharding.clusterRole
configsvr

On shard server:

> db.serverCmdLineOpts().parsed.sharding.clusterRole
shardsvr

Have to be careful as db.serverCmdLineOpts().parsed.sharding.clusterRole is not always defined.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.