dbHash
定义
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.
警告
The dbHash
command obtains a shared (S) lock on the
database, which prevents writes until the command completes.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
重要
M0、M2、M5 和 Flex 集群或无服务器实例不支持此命令。有关更多信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.runCommand( { dbHash: 1, collections: [ <collection1>, ... ] } )
命令字段
该命令接受以下字段:
字段 | 类型 | 说明 |
---|---|---|
| Any type | The command to run. Specify any value. |
| 阵列 | 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. |
行为
Non-Existent Collection
If a collection in the collections
array is non-existent,
dbHash
does not return a hash value for that collection.
限制
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:
字段 | 说明 | |||||
---|---|---|---|---|---|---|
host | The host and port of the | |||||
| A document with the collections and their corresponding hash values.
| |||||
| An array that lists the capped collections. | |||||
| A document with the collections and their corresponding UUID values.
| |||||
| The aggregate hash value for these collections. | |||||
| Number of milliseconds to generate the hash. | |||||
ok operationTime $clusterTime | Returned with every command. See also 响应 for details. |
示例
Return Hash Values for All Collections in a Database
The following example returns the hash value for all collections in the
database test
:
use test db.runCommand( { dbHash: 1 } )
该操作将返回以下文档:
{ "host" : "myHostName.local:27017", "collections" : { "foo" : "d27b769230edc551d869060ec3fb68bd", "inventory" : "ec3d821581ea1bd3aa8196c94b946874", "log" : "d41d8cd98f00b204e9800998ecf8427e", "orders" : "0242c0a128c284ea9576a34db2306c12", "restaurants" : "5dc9b88091c36f0d529567b5b6e3fc92", "zipcodes" : "31ede812bf397509a87359c65bf2a08c" }, "capped" : [ "log" ], "uuids" : { "foo" : UUID("469592fe-3bfe-425e-975f-cedbe0c4741d"), "inventory" : UUID("0830e0ad-cc24-4fc7-80d0-8e22fe45e382"), "log" : UUID("4be024ff-711b-4ab8-836b-dee662e090f1"), "orders" : UUID("755be489-745f-400c-ac3b-f27525ad0108"), "restaurants" : UUID("520b56ec-3276-4904-b6e5-286bc9bfa648"), "zipcodes" : UUID("12e97b70-c174-40af-a178-5d83a241fe20") }, "md5" : "0cb7417ae9d9eb865000b4debdc671da", "timeMillis" : 53, "ok" : 1, "operationTime" : Timestamp(1529208582, 4), "$clusterTime" : { "clusterTime" : Timestamp(1529208582, 4), "signature" : { "hash" : BinData(0,"X3MmevDqUgCVvN1AhnT+fiOL/Lc="), "keyId" : NumberLong("6567898567824900097") } } }
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
:
use test db.runCommand( { dbHash: 1, collections: [ "inventory", "orders" ] } )
该操作将返回以下文档:
{ "host" : "myHostName.local:27017", "collections" : { "inventory" : "ec3d821581ea1bd3aa8196c94b946874", "orders" : "0242c0a128c284ea9576a34db2306c12" }, "capped" : [ ], "uuids" : { "inventory" : UUID("0830e0ad-cc24-4fc7-80d0-8e22fe45e382"), "orders" : UUID("755be489-745f-400c-ac3b-f27525ad0108") }, "md5" : "cb4676f316ff2ff29c701a5edd18afe3", "timeMillis" : 0, "ok" : 1, "operationTime" : Timestamp(1529208801, 1), "$clusterTime" : { "clusterTime" : Timestamp(1529208801, 1), "signature" : { "hash" : BinData(0,"I4z4a4Mgs+tcx0MP5xIU8DYAMB0="), "keyId" : NumberLong("6567898567824900097") } } }