Skip to content

Instantly share code, notes, and snippets.

@cmeiklejohn
Created February 20, 2011 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmeiklejohn/836399 to your computer and use it in GitHub Desktop.
Save cmeiklejohn/836399 to your computer and use it in GitHub Desktop.
Why is this not using the index?
> db.collection.getIndexes();
[
{
"name" : "_id_",
"ns" : "test.collection",
"key" : {
"_id" : 1
}
},
{
"ns" : "test.collection",
"key" : {
"generated_at" : 1,
"captured_at" : 1,
"priority" : -1,
"modified_at" : -1,
"weight" : -1
},
"name" : "generated_at_1_captured_at_1_priority_-1_modified_at_-1_weight_-1"
}
]
>
> db.collection.find({}).sort({'modified_at': -1, 'generated_at': 1, 'weight': -1, 'priority': -1, 'captured_at': 1 }).limit(1).explain();
{
"cursor" : "BasicCursor",
"nscanned" : 83,
"nscannedObjects" : 83,
"n" : 1,
"scanAndOrder" : true,
"millis" : 0,
"indexBounds" : {
}
}
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment