区分连接是mongod 还是mongos 的方式 或者副本集

db.isMaster()


Detect Connections to mongos Instances

To detect if the MongoDB instance that your client is connectedto is mongos, use the isMaster command. When aclient connects to a mongos, isMaster returnsa document with a msg field that holds the stringisdbgrid. For example:

{
   "ismaster" : true,
   "msg" : "isdbgrid",
   "maxBsonObjectSize" : 16777216,
   "ok" : 1
}

If the application is instead connected to a mongod, thereturned document does not include the isdbgrid string.


你可能感兴趣的:(区分连接是mongod 还是mongos 的方式 或者副本集)