- Reference >
- Database Commands >
- Diagnostic Commands >
- dbHash
dbHash¶
On this page
Definition¶
-
dbHash
¶ Returns the hash values of the collections in a database and an MD5 value for these collections.
dbHash
is useful to compare databases acrossmongod
instances, such as across members of replica sets.dbHash
has the following syntax:Field Type Description dbHash
Any type The command to run. Specify any value. collections
array Optional. An array of collection names.
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.
Behavior¶
Non-Existent Collection¶
If a collection in the collections
array is non-existent,
dbHash
does not return a hash value for that collection.
Restrictions¶
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.
Return Document¶
The command returns a document with the following fields:
Field | Description |
---|---|
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. New in version 4.0. |
uuids |
A document with the collections and their corresponding UUID values. New in version 4.0. |
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. |
Examples¶
Return Hash Values for All Collections in a Database¶
The following example returns the hash value for all collections in the
database test
:
The operation returns the following document:
Return Hash Values for Specified Collections in a Database¶
The following example returns the hash value for the collections inventory
and orders
in the database test
:
The operation returns the following document: