Recall & Review
beginner
What is a covered query in MongoDB?
A covered query is a query that can be answered using only the index without reading the actual documents from the collection. This makes the query faster because it avoids fetching full documents.
Click to reveal answer
beginner
How do indexes help covered queries in MongoDB?
Indexes store the fields and their values in a way that MongoDB can quickly find data. If the query only requests fields included in the index, MongoDB can return results directly from the index, making it a covered query.
Click to reveal answer
intermediate
What fields must be included in an index to support a covered query?
All fields used in the query filter and all fields returned in the query projection must be included in the index for the query to be covered.
Click to reveal answer
intermediate
Example: Which index supports this query as a covered query?
Query: db.users.find({age: 30}, {name: 1, age: 1, _id: 0})
An index on {age: 1, name: 1} supports this covered query because it includes the filter field 'age' and the returned field 'name'. The _id field is excluded in projection, so it doesn't need to be in the index.
Click to reveal answer
beginner
Why might a covered query improve performance compared to a normal query?
Because MongoDB can answer the query using only the index, it avoids reading the full documents from disk or memory. This reduces I/O and speeds up query response time.
Click to reveal answer
What does a covered query in MongoDB avoid reading?
✗ Incorrect
Covered queries use only the index to answer the query, so they avoid reading the full documents.
Which fields must be in the index for a query to be covered?
✗ Incorrect
All fields used in the query filter and projection must be in the index for the query to be covered.
If a query returns the _id field but the index does not include _id, is the query covered?
✗ Incorrect
For covered queries, all projected fields including _id must be in the index. Compound indexes do not include _id by default.
What is a benefit of using covered queries?
✗ Incorrect
Covered queries reduce disk I/O and network traffic by returning data directly from the index.
Which MongoDB command helps check if a query is covered?
✗ Incorrect
The explain() command shows query execution details, including whether the query is covered by an index.
Explain what a covered query is and why it improves performance in MongoDB.
Think about how indexes can answer queries without fetching full data.
You got /4 concepts.
Describe the requirements for an index to support a covered query.
Consider which fields the query uses and returns.
You got /4 concepts.