// 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] },
}
StrictProjection
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
, ortrue
/false
.There's a special field
'*'
that can be used to include/exclude all fields.