Skip to content

Instantly share code, notes, and snippets.

@JonKernPA
Created November 26, 2011 23:57
Show Gist options
  • Save JonKernPA/1396544 to your computer and use it in GitHub Desktop.
Save JonKernPA/1396544 to your computer and use it in GitHub Desktop.
Examining Effect of MongoDB index using explain
without a compound index
> db.accounts.find({state: "active"}).limit(15).sort({email: 1}).explain();
{
"cursor" : "BasicCursor",
"nscanned" : 11002,
"nscannedObjects" : 11002,
"n" : 15,
"scanAndOrder" : true,
"millis" : 44,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
with compound index:
************ Account INDEXES ************
state_1_email_1x
state_1_last_name_1x
state_1_last_name_-1x
email_1_name_1x
doctor_num_1x
login_1x
_id_x
msid_1x
last_name_1x
> db.accounts.find({state: "active"}).limit(15).sort({email: 1}).explain();
{
"cursor" : "BtreeCursor state_1_email_1",
"nscanned" : 15,
"nscannedObjects" : 15,
"n" : 15,
"millis" : 2,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"state" : [
[
"active",
"active"
]
],
"email" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment