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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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: