Class Field
java.lang.Object
org.springframework.data.mongodb.core.query.Field
Field projection.
- Author:
- Thomas Risberg, Oliver Gierke, Patryk Wasik, Christoph Strobl, Mark Paluch, Owen Q
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Intermediate builder part for projecting aMongoExpression
to a result field. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Exclude a singlefield
from being returned by the query operation.Exclude one or morefields
from being returned by the query operation.org.bson.Document
int
hashCode()
Include a singlefield
to be returned by the query operation.Include one or morefields
to be returned by the query operation.The array field must appear in the query.project
(MongoExpression expression) Project a givenMongoExpression
to afield
included in the result.projectAs
(MongoExpression expression, String field) Project a givenMongoExpression
to afield
included in the result.Project a$slice
of the arrayfield
using the firstsize
elements.Project a$slice
of the arrayfield
using the firstsize
elements starting atoffset
.
-
Constructor Details
-
Field
public Field()
-
-
Method Details
-
include
Include a singlefield
to be returned by the query operation.- Parameters:
field
- the document field name to be included.- Returns:
this
field projection instance.
-
project
Project a givenMongoExpression
to afield
included in the result.// { 'name' : { '$toUpper' : '$name' } } // native MongoDB expression .project(MongoExpression.expressionFromString("'$toUpper' : '$name'")).as("name"); // Aggregation Framework expression .project(StringOperators.valueOf("name").toUpper()).as("name"); // Aggregation Framework SpEL expression .project(AggregationSpELExpression.expressionOf("toUpper(name)")).as("name");
- Parameters:
expression
- must not be null.- Returns:
- new instance of
Field.FieldProjectionExpression
. Define the target field name throughas(String)
. - Since:
- 3.2
-
projectAs
Project a givenMongoExpression
to afield
included in the result.// { 'name' : { '$toUpper' : '$name' } } // native MongoDB expression .projectAs(MongoExpression.expressionFromString("'$toUpper' : '$name'"), "name"); // Aggregation Framework expression .projectAs(StringOperators.valueOf("name").toUpper(), "name"); // Aggregation Framework SpEL expression .projectAs(AggregationSpELExpression.expressionOf("toUpper(name)"), "name");
- Parameters:
expression
- must not be null.field
- the field name used in the result.- Returns:
- new instance of
Field.FieldProjectionExpression
. - Since:
- 3.2
-
include
Include one or morefields
to be returned by the query operation.- Parameters:
fields
- the document field names to be included.- Returns:
this
field projection instance.- Since:
- 3.1
-
exclude
Exclude a singlefield
from being returned by the query operation.- Parameters:
field
- the document field name to be included.- Returns:
this
field projection instance.
-
exclude
Exclude one or morefields
from being returned by the query operation.- Parameters:
fields
- the document field names to be included.- Returns:
this
field projection instance.- Since:
- 3.1
-
slice
Project a$slice
of the arrayfield
using the firstsize
elements.- Parameters:
field
- the document field name to project, must be an array field.size
- the number of elements to include.- Returns:
this
field projection instance.
-
slice
Project a$slice
of the arrayfield
using the firstsize
elements starting atoffset
.- Parameters:
field
- the document field name to project, must be an array field.offset
- the offset to start at.size
- the number of elements to include.- Returns:
this
field projection instance.
-
elemMatch
-
position
The array field must appear in the query. Only one positional$
operator can appear in the projection and only one array field can appear in the query.- Parameters:
field
- query array field, must not be null or empty.value
-- Returns:
this
field projection instance.
-
getFieldsObject
public org.bson.Document getFieldsObject() -
equals
-
hashCode
public int hashCode()
-