On this page本页内容
dbHash
Returns the hash values of the collections in a database and an MD5 value for these collections. 返回数据库中集合的哈希值和这些集合的MD5值。dbHash
is useful to compare databases across mongod
instances, such as across members of replica sets.dbHash
对于跨mongod
实例(例如跨副本集的成员)比较数据库非常有用。
dbHash
has the following syntax:具有以下语法:
db.runCommand ( { dbHash: 1, collections: [ <collection1>, ... ] } )
dbHash | Any type | |
collections | array |
|
If a collection in the 如果collections
array is non-existent, dbHash
does not return a hash value for that collection.collections
数组中的集合不存在,则dbHash
不会返回该集合的哈希值。
MongoDB drivers automatically set afterClusterTime for operations associated with causally consistent sessions. MongoDB驱动程序自动为与因果一致会话相关的操作设置afterClusterTime
。Starting in MongoDB 4.2, the 从MongoDB 4.2开始,dbHash
command no longer support afterClusterTime. dbHash
命令不再支持afterClusterTime
。As such, 因此,dbHash
cannot be associated with causally consistent sessions.dbHash
不能与因果一致的会话相关联。
The command returns a document with the following fields:该命令返回包含以下字段的文档:
host | mongod instance on which the command is run.mongod 实例的主机和端口。 |
collections |
{ <collection1>: <hash1>, <collection2>: <hash2>, ... } |
capped |
|
uuids |
{ <collection1>: <UUID1>, <collection2>: <UUID2>, ... }
|
md5 | |
timeMillis | |
ok operationTime $clusterTime |
The following example returns the hash value for all collections in the database 以下示例返回数据库test
:test
中所有集合的哈希值:
use test db.runCommand( { dbHash: 1 } )
The operation returns the following document:该操作返回以下文档:
{ "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") } } }
The following example returns the hash value for the collections 以下示例返回数据库inventory
and orders
in the database test
:test
中集合inventory
和orders
的哈希值:
use test db.runCommand( { dbHash: 1, collections: [ "inventory", "orders" ] } )
The operation returns the following document:该操作返回以下文档:
{ "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") } } }