S

Loading…

Type Alias

Projection

Which fields a query returns, as field paths mapped to a flag.

  • { name: 1, "address.city": 1 } returns only those fields (and _id).
  • { passwordHash: 0 } returns everything except those fields.
  • _id is returned unless it is set to 0, and it is the one field that may differ from the rest: { name: 1, _id: 0 } is valid.
  • Inclusion and exclusion cannot be mixed for any other field.

Pass the projection inline, or declare it as const, so the result type can be worked out from it.

type Projection<TDocument extends object> = { readonly [Path in FilterPaths<TDocument> | "_id"]?: ProjectionFlag }

Defined in packages/driver/src/projection.ts:21

Used by#