HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How do I know that I am connected to a config server

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
knowconfigconnectedthathowserver

Problem

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.

Solution

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.

Code Snippets

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

Context

StackExchange Database Administrators Q#126731, answer score: 4

Revisions (0)

No revisions yet.