MongoDB Projection Link to heading

By default, MongoDB returns all fields in matching documents. A projection document can be used to specify exactly which fields do return, and limit the data that Mongo sends to applications.

// Return All Fields in Matching Documents
cosnt cursor = db.collection('inventory').find({
  status: 'A'
})

// Return Specific Fields and _id only
cosnt cursor = db
  .collection('inventory')
  .find({
      status: 'A'
  })
  .project({ item: 1, status: 1})

$project (aggregation) operator Link to heading

$project Passes along the documents with the requested fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.