For AI agents: a documentation index is available at https://www.mongodb.com/es/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Project Fields to Return from Query

Use projection to select which document fields a query returns. You can use the following methods:

By default, queries in MongoDB return all fields in matching documents. To limit the amount of data that MongoDB sends to applications, you can include a projection document to specify or restrict fields to return.

  • When you use a $project aggregation stage it should typically be the last stage in your pipeline, used to specify which fields to return to the client.

    Using a $project stage at the beginning or middle of a pipeline to reduce the number of fields passed to subsequent pipeline stages is unlikely to improve performance, because the database performs this optimization automatically.

  • MongoDB enforces additional restrictions with regards to projections. See Projection Restrictions for details.