|
A likely better way to do this is to use netstat or getShardVersion to get the actual in-memory configdb string that is in use, since this will also work on configsvrs (where sh.status() already works just fine) (compared to getting the parsed server option, which will only work on mongoses).
There could also be an additional note indicating if sh.status() is being run on a configsvr (since that is a little weird), eg.
> sh.status()
|
--- Sharding Status ---
|
sharding version: {
|
"_id" : 1,
|
"minCompatibleVersion" : 6,
|
"currentVersion" : 7,
|
"clusterId" : ObjectId("556f97135efa42f9f4eaedd1")
|
}
|
+ config server connection string (connected to configsvr):
|
+ genique:11113
|
shards:
|
{ "_id" : "shard01", "host" : "genique:11112" }
|
balancer:
|
Currently enabled: yes
|
Currently running: no
|
Failed balancer rounds in last 5 attempts: 0
|
Migration Results for the last 24 hours:
|
No recent migrations
|
databases:
|
{ "_id" : "admin", "primary" : "config", "partitioned" : false }
|
{ "_id" : "config", "primary" : "config", "partitioned" : false }
|
This could be achieved by using the distinction that the netstat command only works on mongos, and so if that fails but getShardVersion (with a known-good ns eg. config.version) works, then we must be on a configsvr.
mongos> db.adminCommand("netstat")
|
{ "configserver" : "genique:11113", "isdbgrid" : 1, "ok" : 1 }
|
mongos> db.adminCommand({"getShardVersion":"config.version"})
|
{ "ok" : 0, "errmsg" : "ns not sharded." }
|
configsvr> db.adminCommand("netstat")
|
{
|
"ok" : 0,
|
"errmsg" : "no such command: netstat",
|
"code" : 59,
|
"bad cmd" : {
|
"netstat" : 1
|
}
|
}
|
configsvr> db.adminCommand({"getShardVersion":"config.version"})
|
{
|
"configServer" : "genique:11113",
|
"global" : Timestamp(0, 0),
|
"inShardedMode" : false,
|
"mine" : Timestamp(0, 0),
|
"ok" : 1
|
}
|
This could be a lot cleaner with better server-side support, but it's hard to say if that'd be worth the effort. eg. allowing getShardVersion to short-circuit and return just configServer if the ns == "" or 1, and then using isdbgrid — or by implementing netstat on mongods, but returning isdbgrid: 0.
|