void testIndex(){ for(int i = 0;i<10000*100;i++) { def radom_ = 5*Math.random() def toInt_ = radom_.intValue() println radom_+"-------"+toInt_ def randAge = (5*Math.random()).intValue() + 20 println randAge def gender = (randAge%2)?"Male":"Female"; db.students.insert(["name":"Will"+i, "gender": gender, "age": randAge]) } }
db.students.createIndex({name: 1},{name:"myIndex"}) db.students.find({"name":"will111115"}).explain("executionStats") db.students.getIndexes() db.students.dropIndex({"name" : 1}) //强制不走索引 db.students.find({"name":"will111115"}).sort({ $natural: 1 }).explain("executionStats")