MongoDB生成测试数据脚本

MongoDB生成测试数据脚本

 

 

for (var i = 1; i <= 9000000; i++) {
   db.testData.insert( { x : i , name: "MACLEAN" , name1:"MACLEAN", name2:"MACLEAN", name3:"MACLEAN"} )
}


db.testData.find().count();

x小于0
db.testData.find({x: {$lt : 0}});

x大于400
db.testData.find({x: {$gt : 400}});

> db.testData.find({x: {$gt : 400}}).explain();




{
	"cursor" : "BasicCursor",
	"isMultiKey" : false,
	"n" : 5860637,
	"nscannedObjects" : 5861039,
	"nscanned" : 5861039,
	"nscannedObjectsAllPlans" : 5861039,
	"nscannedAllPlans" : 5861039,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 45789,
	"nChunkSkips" : 0,
	"millis" : 2598,
	"server" : "macleandeMacBook-Pro.local:27017",
	"filterSet" : false
}
> 
> 
> 
> 
> db.testData.ensureIndex({x:1});




{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> 
> 
> 
> 
> db.testData.find({x: {$gt : 400}}).explain();
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 5860637,
	"nscannedObjects" : 5860637,
	"nscanned" : 5860637,
	"nscannedObjectsAllPlans" : 5860637,
	"nscannedAllPlans" : 5860637,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 45786,
	"nChunkSkips" : 0,
	"millis" : 6165,
	"indexBounds" : {
		"x" : [
			[
				400,
				Infinity
			]
		]
	},
	"server" : "macleandeMacBook-Pro.local:27017",
	"filterSet" : false
}
> db.testData.find({x: {$lt : 0}}).explain();
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"x" : [
			[
				-Infinity,
				0
			]
		]
	},
	"server" : "macleandeMacBook-Pro.local:27017",
	"filterSet" : false
}
> db.testData.find({x: {$lt : 0}}).explain();
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"x" : [
			[
				-Infinity,
				0
			]
		]
	},
	"server" : "macleandeMacBook-Pro.local:27017",
	"filterSet" : false



Comment

*

沪ICP备14014813号

沪公网安备 31010802001379号