Based on the official MongoDB documentation, a covered query is a query in which
As all the fields present in the query are part of an index, MongoDB will match the query conditions and will return the result using same index without even looking into the documents. As indexes are present in RAM, fetching data from indexes is quicker than fetching data by scanning documents.
To test covered queries, consider below document in the users collection
Let’s first create a compound index for the users collection on the fields gender and user_name using the following query
Now, this index will cover below query
This says that for the above query, MongoDB will not look into database documents. Rather it will fetch the needed data from indexed data which is very fast.
As our index does not include _id field, we have explicitly excluded it from result set of our query, as MongoDB by default returns _id field in every query. Therefore the below query will not have been covered inside the index created above
Finally note that an index cannot cover a query if
MongoDB Related Interview Questions
|Python Interview Questions||C & Data Structures Interview Questions|
|Hadoop Interview Questions||Node.js Interview Questions|
|Scala Interview Questions||Socket Programming Interview Questions|
|HBase Interview Questions||Solaris Administrator Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.