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

命令用法如下:

  1. 先切换需要的库use news
  2. 对全库进行dbHashdb.runCommand({dbHash:1}):
{
	"host" : "localhost",
	"collections" : {
		"content" : "241c29add86378f8ca4bedd44f1f5cfb",
		"menu" : "258f3890ebde7b858491440bd8d735d2"
	},
	"capped" : [ ],
	"uuids" : {
		"content" : UUID("2656b5f4-52d5-4c60-8a6d-fea59012db8c"),
		"menu" : UUID("856100b1-b26c-4163-a4da-25178ec1d963")
	},
	"md5" : "ded2bcecad0d01263c663e46c8e9fc1c",
	"timeMillis" : 2,
	"ok" : 1
}

也可以对某个集合进行dbHash,比如对content进行dbHashdb.runCommand({dbHash:1,collections:["content"]})

{
	"host" : "localhost",
	"collections" : {
		"content" : "241c29add86378f8ca4bedd44f1f5cfb"
	},
	"capped" : [ ],
	"uuids" : {
		"content" : UUID("2656b5f4-52d5-4c60-8a6d-fea59012db8c")
	},
	"md5" : "c73deee96afd8393a8b67ab4dfc2e44d",
	"timeMillis" : 0,
	"ok" : 1
}