public final class Projections extends Object
collection.find().projection(fields(include("x", "y"), excludeId()))
Modifier and Type | Method and Description |
---|---|
static <TExpression> |
computed(String fieldName,
TExpression expression)
Creates a projection of a field whose value is computed from the given expression.
|
static Bson |
elemMatch(String fieldName)
Creates a projection that includes for the given field only the first element of an array that matches the query filter.
|
static Bson |
elemMatch(String fieldName,
Bson filter)
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.
|
static Bson |
exclude(List<String> fieldNames)
Creates a projection that excludes all of the given fields.
|
static Bson |
exclude(String... fieldNames)
Creates a projection that excludes all of the given fields.
|
static Bson |
excludeId()
Creates a projection that excludes the _id field.
|
static Bson |
fields(Bson... projections)
Creates a projection that combines the list of projections into a single one.
|
static Bson |
fields(List<Bson> projections)
Creates a projection that combines the list of projections into a single one.
|
static Bson |
include(List<String> fieldNames)
Creates a projection that includes all of the given fields.
|
static Bson |
include(String... fieldNames)
Creates a projection that includes all of the given fields.
|
static Bson |
metaTextScore(String fieldName)
Creates a projection to the given field name of the textScore, for use with text queries.
|
static Bson |
slice(String fieldName,
int limit)
Creates a projection to the given field name of a slice of the array value of that field.
|
static Bson |
slice(String fieldName,
int skip,
int limit)
Creates a projection to the given field name of a slice of the array value of that field.
|
public static <TExpression> Bson computed(String fieldName, TExpression expression)
TExpression
- the expression typefieldName
- the field nameexpression
- the expressionAggregates.project(Bson)
public static Bson include(String... fieldNames)
fieldNames
- the field namespublic static Bson include(List<String> fieldNames)
fieldNames
- the field namespublic static Bson exclude(String... fieldNames)
fieldNames
- the field namespublic static Bson exclude(List<String> fieldNames)
fieldNames
- the field namespublic static Bson excludeId()
public static Bson elemMatch(String fieldName)
fieldName
- the field name whose value is the arraypublic static Bson elemMatch(String fieldName, Bson filter)
fieldName
- the field namefilter
- the filter to applypublic static Bson metaTextScore(String fieldName)
fieldName
- the field namepublic static Bson slice(String fieldName, int limit)
fieldName
- the field namelimit
- the number of elements to project.public static Bson slice(String fieldName, int skip, int limit)
fieldName
- the field nameskip
- the number of elements to skip before applying the limitlimit
- the number of elements to projectpublic static Bson fields(Bson... projections)
projections
- the list of projections to combine