Databases Reference
In-Depth Information
{
"age" : 14,
"username" : ""
},
{
"age" : 14,
"username" : {
}
}
],
[
{
"age" : 14,
"username" : /.*/
},
{
"age" : 14,
"username" : /.*/
}
]
]
}
]
}
If you find that Mongo is using different indexes than you want it to for a query, you
can force it to use a certain index by using hint . For instance, if you want to make sure
MongoDB uses the {"username" : 1, "age" : 1} index on the previous query, you
could say the following:
> db.c.find({"age" : 14, "username" : /.*/}).hint({"username" : 1, "age" : 1})
Hinting is usually unnecessary. MongoDB has a query optimizer and is very clever about
choosing which index to use. When you first do a query, the query optimizer tries out
a number of query plans concurrently. The first one to finish will be used, and the rest
of the query executions are terminated. That query plan will be remembered for future
queries on the same keys. The query optimizer periodically retries other plans, in case
you've added new data and the previously chosen plan is no longer best. The only part
you should need to worry about is giving the query optimizer useful indexes to choose
from.
Index Administration
Metainformation about indexes is stored in the system.indexes collection of each
database. This is a reserved collection, so you cannot insert documents into it or remove
documents from it. You can manipulate its documents only through ensureIndex and
the dropIndexes database command.
The system.indexes collection has detailed information about each index, but the
system.namespaces collection also lists their names. If you look at this collection, you
 
Search WWH ::




Custom Search