Introduction
Covered queries help MongoDB find data quickly by using only the index without looking at the full documents.
db.collection.createIndex({ field1: 1, field2: 1 })
db.collection.find({ field1: value }, { field1: 1, field2: 1, _id: 0 })db.products.createIndex({ category: 1, price: 1 })
db.products.find({ category: "books" }, { category: 1, price: 1, _id: 0 })db.users.createIndex({ username: 1 })
db.users.find({ username: "alice" }, { username: 1, _id: 0 })db.orders.createIndex({ customerId: 1, status: 1 })
db.orders.find({ customerId: 12345 }, { customerId: 1, status: 1, _id: 0 })status and returning status and score fields?status and returns status and score. The index must include all these fields.status and score, so it can cover the query without fetching documents.{ category: 1, price: 1 } on a collection, what will be the output of this query?db.products.find({ category: 'books' }, { category: 1, price: 1, _id: 0 })category and price. The query filters on category and returns category and price only, excluding _id.{ user: 1 } but your query is:db.users.find({ user: 'alice' }, { age: 1, _id: 0 })user. The query filters on user but only returns age, excluding _id.age is not in the index, MongoDB must fetch the full document.age field in the index keys -> Option Adb.orders.find({ status: 'shipped', total: { $gt: 100 } }, { status: 1, total: 1, customer: 1, _id: 0 })status and total, and returns status, total, and customer.status, total, and customer. { status: 1, total: 1, customer: 1 } includes all three.Pass the test and this pattern moves unknown