Type alias Projection

Projection: Record<string, 1 | 0 | boolean | ProjectionSlice>

Specifies which fields should be included/excluded in the returned documents.

If you want stricter type-checking and full auto-complete, see StrictProjection.

Can use 1/0, or true/false.

There's a special field '*' that can be used to include/exclude all fields.

Example

// Include _id, name, and address.state
const projection1: Projection = {
  _id: 0,
  name: 1,
  'address.state': 1,
}

// Exclude the $vector
const projection2: Projection = {
  $vector: 0,
}

// Return array indices 2, 3, 4, and 5
const projection3: Projection = {
  test_scores: { $slice: [2, 4] },
}

See

StrictProjection