db.runCommand()

Definition

  • db.runCommand(command)
  • Provides a helper to run specified database commands. This is the preferred method to issuedatabase commands, as it provides a consistent interface betweenthe shell and drivers.

ParameterTypeDescriptioncommanddocument or string“A database command, specified either in document formor as a string. If specified as a string, db.runCommand()transforms the string into a document.”

To specify a time limit in milliseconds, seeTerminate Running Operations.

Behavior

db.runCommand() runs the command in the context of thecurrent database. Some commands are only applicable in the context ofthe admin database, and you must change your db object tobefore running these commands or use db.adminCommand().

Response

The method returns a response document that contains the followingfields:

FieldDescription
Result fields specific to the command
okA number that indicates whether the command has succeeded(1) or failed (0).
operationTimeThe logical time of the performed operation, represented inMongoDB by the timestamp from the oplog entry. Only for replicasets and sharded clustersIf the command does not generate an oplog entry, e.g. a readoperation, then the operation does not advance the logicalclock. In this case, operationTime returns:- For read concern "local", the timestamp of themost recent entry in the oplog.- For read concern "majority" and"linearizable", the timestamp of the mostrecent majority-acknowledgedentry in the oplog.For operations associated with causally consistentsessions, MongoDB drivers use this timeto automatically set the Read Operations and afterClusterTime.New in version 3.6.
$clusterTimeA document that returns the signed cluster time. Cluster time is alogical time used for ordering of operations. Only for replicasets 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 idof the key used to sign the cluster time.New in version 3.6.