kanders-fatpot
kanders-fatpot

Reputation: 141

Need list of config servers MongoDB

I need to grab (within the C# driver for MongoDB) a list of all the config servers connected to my instance of Mongo-s. Or, failing that, I would settle for a way to grab ALL the servers and a way to go through them one by one telling which are configsvr and which are something else. I was thinking of the getShardMap command, but I still have no idea how to look at a server (programmatically) and decide if it's a configsvr or not.

Thanks.

Upvotes: 2

Views: 2731

Answers (2)

Murali
Murali

Reputation: 51

mongos> db.runCommand("getShardMap")
{
    "map" : {
        "node2:27021" : "node2:27021",
        "node3:27021" : "node3:27021",
        "node4:27021" : "node4:27021",
        "config" : "node2:27019,node3:27019,node4:27019",
        "shard0000" : "node2:27021",
        "shard0001" : "node3:27021",
        "shard0002" : "node4:27021"
    },
    "ok" : 1
}

getShardMap command gives the config string that is passed to mongos server. You can parse the string to get the list of config servers.

Upvotes: 5

kris
kris

Reputation: 23592

The only way I can think of to get this info is to run the getCmdLineOpts command on a mongos and look at the --configdb argument it was passed. I'm not sure how you run admin commands in the C# driver, but I'd imagine it's something like:

db.RunCommand("getCmdLineOpts");

Upvotes: 0

Related Questions