On this page
dbHash
在本页面
Definition
dbHash
- 返回数据库中集合的哈希值和集合列表的 MD5 值。 dbHash对比较mongod个实例之间的数据库很有用,例如针对分片群集或副本集成员的config servers镜像。
dbHash具有以下语法:
db.runCommand ( { dbHash: 1, collections: [ <collection1>, ... ] } )
Field | Type | Description |
---|---|---|
dbHash |
Any type | 要运行的命令。指定任何值。 |
collections |
array | 可选的。集合名称的数组。 |
指定要为其返回哈希值的集合,或者省略或指定一个空数组以返回数据库中所有集合的哈希值。
Behavior
如果collections
数组中的集合不存在,则dbHash不会为该集合返回哈希值。
Examples
返回数据库中所有集合的哈希值
以下示例返回数据库test
中所有集合的哈希值:
use test
db.runCommand( { dbHash: 1 } )
该操作返回以下文档:
{
"host" : "myHostName.local",
"collections" : {
"bar" : "0a8089b7134801ab74d5f1310c27f161",
"foo" : "f49ff19aa6959d96b43961a595ae550e",
"foo2" : "a4f0e61c26af65d7efa0d0ad173db801",
"inventory" : "4f6d23309dcc059232d0e4383fcedfa1",
"orders" : "083def5adf48686a732ee07b8ffaf228",
"restaurants" : "407a4f24cfafa40641e20098929c5632",
"zipcodes" : "679530b9b79d529d79bd143435135f25"
},
"md5" : "2e3b201903d60cdc1eedfd58f4c014d4",
"timeMillis" : 71,
"ok" : 1
}
返回数据库中指定集合的哈希值
下面的示例返回数据库test
中集合foo
和bar
的哈希值:
use test
db.runCommand( { dbHash: 1, collections: [ "foo", "bar" ] } )
该操作返回以下文档:
{
"host" : "myHostName.local",
"collections" : {
"bar" : "0a8089b7134801ab74d5f1310c27f161",
"foo" : "f49ff19aa6959d96b43961a595ae550e"
},
"md5" : "94f296621d5ed4ed35088257ce0c9d99",
"timeMillis" : 0,
"ok" : 1
}
Note
md5
是指定集合的合计哈希值。