Can a query with an index avoid needing to read the table?

22 views
Skip to first unread message

Daniel Harman

unread,
Aug 10, 2012, 2:07:11 PM8/10/12
to mongod...@googlegroups.com
If I have a user object which contains Id and UserName (amongst other things). If I have a compound index on Id and username, given that the index is in memory, will the server be able to avoid even hitting the disk if I'm query for a UserName by Id?

Thanks,

Dan

Scott Hernandez

unread,
Aug 10, 2012, 2:18:55 PM8/10/12
to mongod...@googlegroups.com
Yes, that is called a covered index or query. You will need to exclude
the _id field, to return only the username:

http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-CoveredIndexes
http://www.mongodb.org/display/DOCS/Indexes
> --
> 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
> See also the IRC channel -- freenode.net#mongodb

Daniel Harman

unread,
Aug 10, 2012, 6:47:21 PM8/10/12
to mongod...@googlegroups.com
Thanks Scott. I had no idea what to search for without knowing the correct term!
Reply all
Reply to author
Forward
0 new messages