On this page本页内容
dbHash
¶Returns the hash values of the collections in a database and an MD5 value for these collections. dbHash
is useful to compare databases across mongod
instances, such as across members of replica sets.
dbHash
has the following syntax:语法如下所示:
dbHash |
Any type | The command to run. Specify any value. |
collections |
array |
Either specify the collections for which to return the hash values, or omit or specify an empty array to return the hash values for all collections in the database. |
If a collection in the collections
array is non-existent, dbHash
does not return a hash value for that collection.
MongoDB drivers automatically set afterClusterTime for operations associated with causally consistent sessions. Starting in MongoDB 4.2, the dbHash
command no longer support afterClusterTime. As such, dbHash
cannot be associated with causally consistent sessions.
The command returns a document with the following fields:
host | The host and port of the mongod instance on which the command is run. |
collections |
A document with the collections and their corresponding hash values. |
capped |
An array that lists the capped collections.
|
uuids |
A document with the collections and their corresponding UUID values.
|
md5 |
The aggregate hash value for these collections. |
timeMillis |
Number of milliseconds to generate the hash. |
ok operationTime $clusterTime |
Returned with every command. See also Response for details. |
The following example returns the hash value for all collections in the database test
:
The operation returns the following document:
The following example returns the hash value for the collections inventory
and orders
in the database test
:
The operation returns the following document: