Database Manual / Reference / Database Commands / Sharding

isdbgrid (database command数据库命令)

Definition定义

isdbgrid

This command verifies that a process is a mongos.此命令验证进程是否为mongos

If you issue the isdbgrid command when connected to a mongos, the response document includes the isdbgrid field set to 1.如果您在连接到mongos时发出isdbgrid命令,响应文档中会包含设置为1isdbgrids字段。

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand(
{
isdbgrid: 1
}
)

Output输出

The returned document is similar to the following:返回的文档类似于以下内容:

{ "isdbgrid" : 1, "hostname" : "app.example.net", "ok" : 1 }

If you issue the isdbgrid command when connected to a mongod, MongoDB returns an error document. 如果你在连接到mongod时发出isdbgrid命令,MongoDB会返回一个错误文档。The isdbgrid command is not available to mongod. isdbgrid命令对mongod不可用。The error document, however, also includes a line that reads "isdbgrid" : 1, just as in the document returned for a mongos. The error document is similar to the following:然而,错误文档中还包含一行"isdbgrid" : 1,就像在为mongos返回的文档中一样。错误文档类似于以下内容:

{
"errmsg" : "no such cmd: isdbgrid",
"bad cmd" : {
"isdbgrid" : 1
},
"ok" : 0
}

You can instead use the hello command to determine connection to a mongos. When connected to a mongos, the hello command returns a document that contains the string isdbgrid in the msg field.您可以使用hello命令来确定与mongos的连接。当连接到mongos时,hello命令返回一个文档,该文档在msg字段中包含字符串isdbgrid