You can verify that the index is actually used without access to the disk.
Let's say you want to count entries with the name: "Andrew"
You guarantee the index by name (how you did it) and
db.users.find({name:"andrei"}, {_id:0, name:1}).count()
you can verify that this is the fastest way to count (with the exception of precalculation) by checking that
db.users.find({name:"andrei"}, {_id:0, name:1}).explain()
displays the index_only field set to true.
This trick ensures that your query will only retrieve records from ram (index) and not from disk.
kamaradclimber Oct 05 '11 at 12:40 2011-10-05 12:40
source share