Package com.mongodb.client.model
Class Projections
-
- com.mongodb.client.model.Projections
-
public final class Projections extends
A factory for projections. A convenient way to use this class is to statically import all of its methods, which allows usage like:collection.find().projection(fields(include("x", "y"), excludeId()))
- Since:
- 3.0
- MongoDB documentation
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <TExpression>
BsonfieldName, TExpression expression)
Creates a projection of a field whose value is computed from the given expression.static Bson
fieldName)
Creates a projection that includes for the given field only the first element of an array that matches the query filter.static Bson
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
... fieldNames)
Creates a projection that excludes all of the given fields.static Bson
<> fieldNames)
Creates a projection that excludes all of the given fields.static Bson
excludeId()
Creates a projection that excludes the _id field.static Bson
<? extends Bson> projections)
Creates a projection that combines the list of projections into a single one.static Bson
fields(Bson... projections)
Creates a projection that combines the list of projections into a single one.static Bson
... fieldNames)
Creates a projection that includes all of the given fields.static Bson
<> fieldNames)
Creates a projection that includes all of the given fields.static Bson
fieldName)
Creates a projection to the given field name of the textScore, for use with text queries.static Bson
fieldName, int limit)
Creates a projection to the given field name of a slice of the array value of that field.static Bson
fieldName, int skip, int limit)
Creates a projection to the given field name of a slice of the array value of that field.
-
-
-
Method Detail
-
computed
public static <TExpression> fieldName, TExpression expression)
Creates a projection of a field whose value is computed from the given expression. Projection with an expression is only supported using the $project aggregation pipeline stage.- Type Parameters:
TExpression
- the expression type- Parameters:
fieldName
- the field nameexpression
- the expression- Returns:
- the projection
- See Also:
Aggregates.project(Bson)
-
include
public static ... fieldNames)
Creates a projection that includes all of the given fields.- Parameters:
fieldNames
- the field names- Returns:
- the projection
-
include
public static <> fieldNames)
Creates a projection that includes all of the given fields.- Parameters:
fieldNames
- the field names- Returns:
- the projection
-
exclude
public static ... fieldNames)
Creates a projection that excludes all of the given fields.- Parameters:
fieldNames
- the field names- Returns:
- the projection
-
exclude
public static <> fieldNames)
Creates a projection that excludes all of the given fields.- Parameters:
fieldNames
- the field names- Returns:
- the projection
-
excludeId
public static Bson excludeId()
Creates a projection that excludes the _id field. This suppresses the automatic inclusion of _id that is the default, even when other fields are explicitly included.- Returns:
- the projection
-
elemMatch
public static fieldName)
Creates a projection that includes for the given field only the first element of an array that matches the query filter. This is referred to as the positional $ operator.- Parameters:
fieldName
- the field name whose value is the array- Returns:
- the projection
- MongoDB documentation
-
elemMatch
public static 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.- Parameters:
fieldName
- the field namefilter
- the filter to apply- Returns:
- the projection
- MongoDB documentation
-
metaTextScore
public static fieldName)
Creates a projection to the given field name of the textScore, for use with text queries.- Parameters:
fieldName
- the field name- Returns:
- the projection
- MongoDB documentation
-
slice
public static fieldName, int limit)
Creates a projection to the given field name of a slice of the array value of that field.- Parameters:
fieldName
- the field namelimit
- the number of elements to project.- Returns:
- the projection
- MongoDB documentation
-
slice
public static fieldName, int skip, int limit)
Creates a projection to the given field name of a slice of the array value of that field.- Parameters:
fieldName
- the field nameskip
- the number of elements to skip before applying the limitlimit
- the number of elements to project- Returns:
- the projection
- MongoDB documentation
-
fields
public static Bson fields(Bson... projections)
Creates a projection that combines the list of projections into a single one. If there are duplicate keys, the last one takes precedence.- Parameters:
projections
- the list of projections to combine- Returns:
- the combined projection
-
fields
public static <? extends Bson> projections)
Creates a projection that combines the list of projections into a single one. If there are duplicate keys, the last one takes precedence.- Parameters:
projections
- the list of projections to combine- Returns:
- the combined projection
-
-