ITPub博客

首页 > 数据库 > NoSQL > MongoDB数据比较工具dbHash介绍

MongoDB数据比较工具dbHash介绍

原创 NoSQL 作者:chenfeng 时间:2016-05-13 09:39:44 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/15498/viewspace-2099041/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
交流MySQL,PolarDB/PolarDB-X,PostgreSQL,MongoDB和Redis技术。

注册时间:2015-12-07

  • 博文量
    784
  • 访问量
    2690812