java.lang.Object
org.springframework.data.mongodb.core.query.Field

public class Field extends Object
Field projection.
Author:
Thomas Risberg, Oliver Gierke, Patryk Wasik, Christoph Strobl, Mark Paluch, Owen Q
  • Constructor Details

    • Field

      public Field()
  • Method Details

    • include

      public Field include(String field)
      Include a single field to be returned by the query operation.
      Parameters:
      field - the document field name to be included.
      Returns:
      this field projection instance.
    • project

      public Field.FieldProjectionExpression project(MongoExpression expression)
      Project a given MongoExpression to a field 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 through as(String).
      Since:
      3.2
    • projectAs

      public Field projectAs(MongoExpression expression, String field)
      Project a given MongoExpression to a field 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

      public Field include(String... fields)
      Include one or more fields 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

      public Field exclude(String field)
      Exclude a single field from being returned by the query operation.
      Parameters:
      field - the document field name to be included.
      Returns:
      this field projection instance.
    • exclude

      public Field exclude(String... fields)
      Exclude one or more fields 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

      public Field slice(String field, int size)
      Project a $slice of the array field using the first size 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

      public Field slice(String field, int offset, int size)
      Project a $slice of the array field using the first size elements starting at offset.
      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

      public Field elemMatch(String field, Criteria elemMatchCriteria)
    • position

      public Field position(String field, int value)
      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

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object