Type alias StrictProjection<Schema>

StrictProjection<Schema>: {
    [K in keyof ToDotNotation<WithId<Schema>>]?: any[] extends ToDotNotation<WithId<Schema>>[K]
        ? 1 | 0 | boolean | ProjectionSlice
        : 1 | 0 | boolean
} & {
    *?: 1 | 0 | boolean;
}

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

Can use 1/0, or true/false.

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

Type Parameters

Type declaration

  • Optional *?: 1 | 0 | boolean

Example

await collection.findOne({}, {
  projection: {
  _id: 0,
  name: 1,
  'address.state': 1,
  } satisfies StrictProjection<SomeDoc>,
});

await collection.findOne({}, {
  projection: {
  $vector: 0,
  } satisfies StrictProjection<SomeDoc>,
});

await collection.findOne({}, {
  projection: {
  test_scores: { $slice: [2, 4] },
  } satisfies StrictProjection<SomeDoc>,
});

See

Projection