snippetMinor
How do I know that I am connected to a config server
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:
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.
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.
I can check the process to differentiate between mongod and mongos:
> db.serverStatus().process;
mongodNow 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:
On shard server:
Have to be careful as
On config server:
> db.serverCmdLineOpts().parsed.sharding.clusterRole
configsvrOn shard server:
> db.serverCmdLineOpts().parsed.sharding.clusterRole
shardsvrHave 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
shardsvrContext
StackExchange Database Administrators Q#126731, answer score: 4
Revisions (0)
No revisions yet.