MongoProjections
Definition of the projections in Bson that are used in MongoDB collection queries to select specific fields.
computed
computed(fieldName: string, expression: org.bson.conversions.Bson) : org.bson.conversions.Bson
Description
Creates a projection that adds a computed field to the result.
How To Use
_mongo.projections().computed('fullName', expression);
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldName | string | The output field name. |
| expression | org.bson.conversions.Bson | The computed field expression. |
Return
( org.bson.conversions.Bson )
The projection.
elemMatch
elemMatch(fieldName: string) : org.bson.conversions.Bson
Description
Creates a projection that includes for the given field only the first element of an array that matches the query filter.
How To Use
const docs = collection.find(_mongo.filters().gt('array', 7)).projection(_mongo.projections().elemMatch('array')).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldName | string | The field name whose value is the array. |
Return
( org.bson.conversions.Bson )
The projection.
elemMatch(fieldName: string, filter: org.bson.conversions.Bson) : org.bson.conversions.Bson
Description
Creates a projection that includes for the given field only the first element of the array value of that field that matches the given query filter.
How To Use
const docs = collection.find().projection(
_mongo.projections().elemMatch(
"orders",
_mongo.filters().eq("status", "pending")
)
).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldName | string | The field name. |
| filter | org.bson.conversions.Bson | The filter to apply. |
Return
( org.bson.conversions.Bson )
The projection.
exclude
exclude(fieldNames: string[]) : org.bson.conversions.Bson
Description
Creates a projection that excludes all of the given fields.
How To Use
const docs = collection.find().projection(_mongo.projections().exclude('internalField')).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldNames | string[] | The field names. |
Return
( org.bson.conversions.Bson )
The projection.
exclude(fieldNames: java.util.List<string>) : org.bson.conversions.Bson
Description
Creates a projection that excludes all fields from a list.
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldNames | java.util.List | The list of field names. |
Return
( org.bson.conversions.Bson )
The projection.
excludeId
excludeId() : org.bson.conversions.Bson
Description
Creates a projection that excludes the _id field.
How To Use
const docs = collection.find().projection(_mongo.projections().excludeId()).all();
Return
( org.bson.conversions.Bson )
The projection.
fields
fields(projections: org.bson.conversions.Bson[]) : org.bson.conversions.Bson
Description
Creates a projection that combines the list of projections into a single one. If there are duplicate keys, the last one takes precedence.
How To Use
const docs = collection.find().projection( _mongo.projections().fields(
_mongo.projections().include("name", "quantity"),
_mongo.projections().excludeId()
)
).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| projections | org.bson.conversions.Bson[] | The list of projections to combine. |
Return
( org.bson.conversions.Bson )
The combined projection.
fields(projections: java.util.List<?>) : org.bson.conversions.Bson
Description
Creates a projection that combines the list of projections from a list.
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| projections | java.util.List | The list of projections to combine. |
Return
( org.bson.conversions.Bson )
The combined projection.
include
include(fieldNames: string[]) : org.bson.conversions.Bson
Description
Creates a projection that includes all of the given fields.
How To Use
const docs = collection.find().projection(_mongo.projections().include('name', 'quantity')).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldNames | string[] | The field names. |
Return
( org.bson.conversions.Bson )
The projection.
include(fieldNames: java.util.List<string>) : org.bson.conversions.Bson
Description
Creates a projection that includes all fields from a list.
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldNames | java.util.List | The list of field names. |
Return
( org.bson.conversions.Bson )
The projection.
slice
slice(fieldName: string, limit: int) : org.bson.conversions.Bson
Description
Creates a projection that returns only the first N elements of an array.
How To Use
const docs = collection.find().projection(_mongo.projections().slice('tags', 5)).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldName | string | The field name whose value is the array. |
| limit | int | The number of elements to return. |
Return
( org.bson.conversions.Bson )
The projection.
slice(fieldName: string, skip: int, limit: int) : org.bson.conversions.Bson
Description
Creates a projection that skips N elements and returns the next M elements of an array.
How To Use
const docs = collection.find().projection(_mongo.projections().slice('tags', 2, 5)).all();
Attributes
| NAME | TYPE | DESCRIPTION |
|---|---|---|
| fieldName | string | The field name whose value is the array. |
| skip | int | The number of elements to skip. |
| limit | int | The number of elements to return. |
Return
( org.bson.conversions.Bson )
The projection.