MongoDB - Covered Queries

MongoDB - Covered Queries

What is a Covered Query?

As per the official MongoDB documentation, a covered query is a query in which
  • All the fields in the query are part of an index.
  • All the fields returned in the query are in the same index.

Since all the fields present in the query are part of an index, MongoDB matches the query conditions and returns the result using the same index without actually looking inside the documents.

Using Covered Queries

To test covered queries, consider the following document in the users collection
    "_id": ObjectId("12544454545454587"),
    "contact": "987654321",
    "dob": "01-06-1984",
    "gender": "F",
    "name": "Anglina",
    "user_name": "anglina58"
Now, this index will cover the following query
MongoDB would not go looking into database documents.

Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.