1代表正向排序,-1代表反向排序
?
db.jerome_collection.ensureIndex({x:1})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
db.jerome_collection.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "jerome.jerome_collection"
},
{
"v" : 1,
"key" : {
"x" : 1
},
"name" : "x_1",
"ns" : "jerome.jerome_collection"
}
]
?
?
?
索引虽然会使写入的数度变慢,但是查询的速度变快了。