Ch. 12 · MongoDB

MongoDB Projections and Covered Queries

Return only the fields you need, exclude _id when unused, and build a covering index that answers a query without fetching documents.

~2 min readintermediateupdated Oct 5, 2026

A projection limits which fields are returned, which cuts network and memory use. When the index itself contains every field the query needs, MongoDB answers without reading the documents at all, which is a covered query and much faster.

Before you start

You should be comfortable with find, indexes and explain. This article uses the MongoDB shell.

Step-by-step walkthrough

Step 1: Project only the needed fields

{ name: 1, _id: 0 } returns just name. Returning whole documents wastes bandwidth and working-set memory, especially when the client only needs a few fields. Exclude _id when it is not used, since it is included by default.

Step 2: Align the projection with the index

If the filter and the projection fields are all in the index, the query is covered. For example, an index on { status: 1, name: 1 } covers find({ status: 'active' }, { name: 1, _id: 0 }) because both fields are present and _id is excluded.

Step 3: Confirm with explain

explain('executionStats') shows totalDocsExamined. A covered query examines zero documents, proving the index alone answered it. If documents are examined, add the missing field to the index or drop it from the projection.

Worked scenario

The query is covered because the index holds both fields.

db.users.createIndex({ status: 1, name: 1 });
db.users
  .find({ status: 'active' }, { name: 1, _id: 0 })
  .explain('executionStats');
JavaScript

Walk through the example

The filter is on status and the projection returns name, both of which are in the index, and _id is excluded so it need not be fetched. The executionStats output shows totalDocsExamined: 0, which is the signature of a covered query. Adding _id: 1 back would force a document fetch.

Common mistake

Returning entire documents and filtering in the client, which defeats the database’s ability to reduce work. Another is a projection that omits a field to get coverage but then needs it in the response, forcing a second lookup.

Verify the behavior

Run the covered query and confirm totalDocsExamined is zero. Add _id: 1 and confirm it becomes non-zero, proving the fetch. Compare latency and bytes returned for a full document versus a projection.

Interview exercise

What does a covered query require?

Answer and reasoning

Every field the query uses — the filter keys, the sort keys and the returned projection — must be present in the index, and any field not in the index must be excluded from the result. When those hold, the engine answers from the index alone without reading documents, which is why excluding _id matters so often.

Continue learning

Compare index usage in Compound indexes and diagnostics in Explain diagnostics. Read the MongoDB covered query documentation and try the MongoDB interview questions.

More in MongoDB

read ✓MongoDB · mid

MongoDB Bulk Writes

Batch inserts and updates with bulkWrite, choose ordered or unordered, and handle partial failures correctly.

~2 min readread →
read ✓MongoDB · mid

MongoDB Capped Collections

Use capped collections for fixed-size, insertion-ordered logs, and know why documents cannot grow.

~2 min readread →
esc