Databases Reference
In-Depth Information
Now, let's suppose we have an index on the "age" key and we're querying for users in
their 20s. If we run explain on this query, we'll see the following:
> db.c.find({age : {$gt : 20, $lt : 30}}).explain()
{
"cursor" : "BtreeCursor age_1",
"indexBounds" : [
[
{
"age" : 20
},
{
"age" : 30
}
]
],
"nscanned" : 14,
"nscannedObjects" : 12,
"n" : 12,
"millis" : 1,
"allPlans" : [
{
"cursor" : "BtreeCursor age_1",
"indexBounds" : [
[
{
"age" : 20
},
{
"age" : 30
}
]
]
}
]
}
There are some differences here, because this query uses an index. Thus, some of
explain 's outputted keys have changed:
"cursor" : "BtreeCursor age_1"
This query is not using a BasicCursor , like the first query was. Indexes are stored
in data structures called B-trees, so, when a query uses an index, it uses a special
type of cursor called a BtreeCursor.
This value also identifies the name of the index being used: age_1 . Using this name,
we could query the system.indexes collection to find out more about this index
(e.g., whether it is unique or what keys it includes):
> db.system.indexes.find({"ns" : "test.c", "name" : "age_1"})
{
"_id" : ObjectId("4c0d211478b4eaaf7fb28565"),
"ns" : "test.c",
"key" : {
"age" : 1
 
Search WWH ::




Custom Search