MongoDB数据比较工具dbHash介绍

dbHash主要是用来比较MongoDB数据是否一致,例如升级版本前后的数据比较,主要是为了确认数据在升级后是完全恢复无误的。

命令用法如下:

> use test
switched to db test
对整个test数据库执行dbHash:
> db.runCommand({dbHash:1})
{
        "numCollections" : 6,
        "host" : "XCC-Duanshufeng",
        "collections" : {
                "articles" : "00ac934ceff133bb0098b1c35a75bdea",
                "books" : "bc52524239790921537157b52098fe84",
                "chenfeng" : "12ed2905e982feca3615bfae7b2ed588",
                "users" : "84b7f9fc8c2ea9fcabc2286ad22e9303"
        },
        "md5" : "6f8d391996f5d9860ddc5a075d3f7de3",
        "timeMillis" : 5548,
        "fromCache" : [ ],
        "ok" : 1
}
>

> show collections
articles
books
chenfeng
system.indexes
users

对test 数据库某个集合执行dbHash:
> db.runCommand({dbHash:1,collections:["books","chenfeng"]})
{
        "numCollections" : 6,
        "host" : "XCC-Duanshufeng",
        "collections" : {
                "books" : "bc52524239790921537157b52098fe84",
                "chenfeng" : "12ed2905e982feca3615bfae7b2ed588"
        },
        "md5" : "cd9a81b96e0921007d94ddb3633d9af0",
        "timeMillis" : 825,
        "fromCache" : [ ],
        "ok" : 1
}
>



官网对该工具的解释如下:
dbHash
Returns the hash values of the collections in a database and an MD5 value for the list of collections. 
dbHash is useful to compare databases across mongod instances, such as mirrored config servers for sharded clusters or members of replica sets.


dbHash has the following syntax:

db.runCommand ( { dbHash: 1, collections: [ <collection1>, ... ] } )

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15498/viewspace-2099041/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15498/viewspace-2099041/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值