| Steps To Reproduce: |
Insert this set of test data:
> db.rooms.find()
|
{ "_id" : ObjectId("53ad206e1d8f2d8351182830"), "id" : 1, "from" : ISODate("2014-06-26T00:00:00Z"), "to" : ISODate("2014-06-28T00:00:00Z") }
|
{ "_id" : ObjectId("53ad276f1d8f2d8351182831"), "id" : 1, "from" : ISODate("2014-06-24T00:00:00Z"), "to" : ISODate("2014-07-01T00:00:00Z") }
|
{ "_id" : ObjectId("53ad28ad1d8f2d8351182832"), "id" : 1, "from" : ISODate("2014-06-20T00:00:00Z"), "to" : ISODate("2014-06-28T00:00:00Z") }
|
{ "_id" : ObjectId("53ad28c61d8f2d8351182833"), "id" : 1, "from" : ISODate("2014-06-20T00:00:00Z"), "to" : ISODate("2014-07-03T00:00:00Z") }
|
{ "_id" : ObjectId("53ad29971d8f2d8351182834"), "id" : 1, "from" : ISODate("2014-06-20T00:00:00Z"), "to" : ISODate("2014-06-21T00:00:00Z") }
|
Create these indexes:
> db.rooms.getIndexes()
|
[
|
{
|
"v" : 1,
|
"key" : {
|
"_id" : 1
|
},
|
"name" : "_id_",
|
"ns" : "test.rooms"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"id" : 1
|
},
|
"name" : "id_1",
|
"ns" : "test.rooms"
|
}
|
]
|
And then run this query:
> db.rooms.find({id:1}).sort({id:1}).limit(2).explain()
|
{
|
"cursor" : "BtreeCursor id_1",
|
"isMultiKey" : false,
|
"n" : 2,
|
"nscannedObjects" : 2,
|
"nscanned" : 3,
|
"nscannedObjectsAllPlans" : 2,
|
"nscannedAllPlans" : 3,
|
"scanAndOrder" : false,
|
"indexOnly" : false,
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"indexBounds" : {
|
"id" : [
|
[
|
1,
|
1
|
]
|
]
|
},
|
"server" : "ubuntu:27017",
|
"filterSet" : false
|
}
|
with or without the sort will result in the same answer.
|