db.runCommand()

On this page本页内容

Definition定义

db.runCommand(command)

Provides a helper to run specified database commands. 提供运行指定数据库命令的帮助程序。This is the preferred method to issue database commands, as it provides a consistent interface between the shell and drivers.这是发出数据库命令的首选方法,因为它在shell和驱动程序之间提供了一致的接口。

Parameter参数Type类型Description描述
commanddocument or string"A database command, specified either in document form or as a string. 数据库命令,以文档形式或字符串形式指定。If specified as a string, db.runCommand() transforms the string into a document."如果指定为字符串,db.runCommand()将字符串转换为文档。“

To specify a time limit in milliseconds, see Terminate Running Operations.要以毫秒为单位指定时间限制,请参阅终止正在运行的操作

Behavior行为

db.runCommand() runs the command in the context of the current database. 在当前数据库的上下文中运行命令。Some commands are only applicable in the context of the admin database, and you must change your db object to before running these commands or use db.adminCommand().有些命令仅适用于admin数据库的上下文,在运行这些命令或使用db.adminCommand()之前,必须更改db对象。

Response回答

The method returns a response document that contains the following fields:该方法返回包含以下字段的响应文档:

Field字段Description描述
<command result>Result fields specific to the command that was run.特定于运行的命令的结果字段。
okA number that indicates whether the command has succeeded (1) or failed (0). 指示命令是成功(1)还是失败(0)的数字。
operationTime

The logical time of the operation. MongoDB uses the logical time to order operations. Only for replica sets and sharded clusters.操作的逻辑时间。MongoDB使用逻辑时间对操作进行排序。仅适用于副本集和分片群集。

If the command does not generate an oplog entry, e.g. a read operation, then the operation does not advance the logical clock. 如果命令没有生成oplog条目,例如读取操作,则该操作不会提前逻辑时钟。In this case, operationTime returns:在这种情况下,operationTime返回:

For operations associated with causally consistent sessions, MongoDB drivers use this time to automatically set the Read Operations and afterClusterTime.对于与因果一致会话相关联的操作,MongoDB驱动程序使用此时间自动设置读取操作和afterClusterTime

$clusterTime

A document that returns the signed cluster time. 返回签名群集时间的文档。Cluster time is a logical time used for ordering of operations. 群集时间是用于排序操作的逻辑时间。Only for replica sets and sharded clusters. 仅适用于副本集和分片群集。For internal use only.仅供内部使用。

The document contains the following fields:该文档包含以下字段:

  • clusterTime: timestamp of the highest known cluster time for the member.:成员的最高已知群集时间的时间戳。
  • signature: a document that contains the hash of the cluster time and the id of the key used to sign the cluster time.:一个包含集群时间哈希和用于签名集群时间的密钥id的文档。
←  db.rotateCertificates()db.serverBuildInfo() →