Validate Command

Use this command to check that a collection is valid (not corrupt) and to get various statistics.

This command scans the entire collection and its indexes and will be very slow on large datasets.

option description
full Validates everything – new in 2.0.0
scandata Validates basics (index/collection-stats) and document headers
Blocking
This is a blocking operation (like Repair Database Command).

From the mongo shell:

> db.foo.validate({full:true})
{
	"ns" : "test.foo",
	"firstExtent" : "0:109c00 ns:test.foo",
	"lastExtent" : "0:2e0d00 ns:test.foo",
	"extentCount" : 3,
	"extents" : [
		{
			"loc" : "0:109c00",
			"xnext" : "0:192000",
			"xprev" : "null",
			"nsdiag" : "test.foo",
			"size" : 12288,
			"firstRecord" : "0:109cb0",
			"lastRecord" : "0:10cb90"
		},
		{
			"loc" : "0:192000",
			"xnext" : "0:2e0d00",
			"xprev" : "0:109c00",
			"nsdiag" : "test.foo",
			"size" : 49152,
			"firstRecord" : "0:1920b0",
			"lastRecord" : "0:19df00"
		},
		{
			"loc" : "0:2e0d00",
			"xnext" : "null",
			"xprev" : "0:192000",
			"nsdiag" : "test.foo",
			"size" : 196608,
			"firstRecord" : "0:2e0db0",
			"lastRecord" : "0:30c820"
		}
	],
	"datasize" : 224112,
	"nrecords" : 1001,
	"lastExtentSize" : 196608,
	"padding" : 1,
	"firstExtentDetails" : {
		"loc" : "0:109c00",
		"xnext" : "0:192000",
		"xprev" : "null",
		"nsdiag" : "test.foo",
		"size" : 12288,
		"firstRecord" : "0:109cb0",
		"lastRecord" : "0:10cb90"
	},
	"objectsFound" : 1001,
	"invalidObjects" : 0,
	"bytesWithHeaders" : 240128,
	"bytesWithoutHeaders" : 224112,
	"deletedCount" : 1,
	"deletedSize" : 17392,
	"nIndexes" : 1,
	"keysPerIndex" : {
		"test.foo.$_id_" : 1001
	},
	"valid" : true,
	"errors" : [ ],
	"ok" : 1
}
Example From Driver

From a driver one might invoke the driver's equivalent of:

> db.$cmd.findOne({validate:"foo" } );
> db.$cmd.findOne({validate:"foo", full:true});

Labels

command command Delete
validate validate Delete
admin admin Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

PLEASE POST QUESTIONS IN THE FORUMS: http://groups.google.com/group/mongodb-user. Post tips and clarifications here.

blog comments powered by Disqus