The index will include the value you are looking for and is ordered
the way you want. Having an index just on the sorted field doesn't
help as it can't be used (effectively) if you are searching for other
values.
Any $where cannot use an index so it will have to inspect every
document for those criteria, and all javascript runs in a single
thread; not good for concurrency for large number of docs or queries.
> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>
--
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
I think you actually want to index like this:
db.data.ensureIndex({"key":1, "timestamp" : 1})
A query can only use a single index. If you want to filter and sort
with a single index you should use a compound index as has been
suggested.
One index per field might not be that useful (since a query can only
use a single index) if you are always using more than one query
criteria. You might want to read up here:
http://www.mongodb.org/display/DOCS/Indexes