Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Created July 28, 2014 19:10
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 pfreixes/2b214ef3b8fc96f62825 to your computer and use it in GitHub Desktop.
Save pfreixes/2b214ef3b8fc96f62825 to your computer and use it in GitHub Desktop.
Get benefit of current BTree implemenation of indexes in Mongodb
> db.test.find().count()
13
> db.test.find()
{ "_id" : "01-02" }
{ "_id" : "01-01" }
{ "_id" : "01-03" }
{ "_id" : "02-01" }
{ "_id" : "02-02" }
{ "_id" : "02-03" }
{ "_id" : "03-01" }
{ "_id" : "03-02" }
{ "_id" : "03-03" }
{ "_id" : "03-04" }
{ "_id" : "03-05" }
{ "_id" : "03-06" }
{ "_id" : "01-04" }
> db.test.find({_id: /^02-/}).count()
3
> db.test.find({_id: /^02-/}).explain()
{
"cursor" : "BtreeCursor _id_ multi",
"nscanned" : 4,
"nscannedObjects" : 3,
"n" : 3,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"_id" : [
[
"02-",
"02."
],
[
/^02-/,
/^02-/
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment