Class Miscellaneous

java.lang.Object
dev.morphia.aggregation.expressions.Miscellaneous

public final class Miscellaneous extends Object
Defines miscellaneous operators for aggregations.
Since:
2.2
  • Method Details

    • getField

      public static GetFieldExpression getField(String field)
      Returns the value of a specified field from a document. If you don't specify an object, $getField returns the value of the field from $$CURRENT.
      Parameters:
      field - the field name
      Returns:
      the new expression
      Since:
      2.3
      Since server release
      5.0
      MongoDB documentation
      Aggregration Expression: $getField
    • getField

      public static GetFieldExpression getField(Object field)
      Returns the value of a specified field from a document. If you don't specify an object, $getField returns the value of the field from $$CURRENT.
      Parameters:
      field - the expression yielding the field name
      Returns:
      the new expression
      Since:
      2.3
      Since server release
      5.0
      MongoDB documentation
      Aggregration Expression: $getField
    • rand

      public static Expression rand()
      Returns a random float between 0 and 1.
      Returns:
      the filter
      Since:
      2.2
      Since server release
      4.4.2
      MongoDB documentation
      Aggregration Expression: $rand
    • sampleRate

      public static Filter sampleRate(double rate)
      Matches a random selection of input documents. The number of documents selected approximates the sample rate expressed as a percentage of the total number of documents.
      Parameters:
      rate - the rate to check against
      Returns:
      the filter
      Since:
      2.2
      Since server release
      4.4.2
      MongoDB documentation
      Aggregration Expression: $sampleRate
    • setField

      public static Expression setField(Object field, Object input, Object value)
      Adds, updates, or removes a specified field in a document.
      Parameters:
      field - Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant.
      input - Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined.
      value - The value that you want to assign to field. value can be any valid expression. Set to $$REMOVE to remove field from the input document.
      Returns:
      the new expression
      Since:
      2.3
      Since server release
      5.0
      MongoDB documentation
      Aggregration Expression: $setField
    • unsetField

      public static Expression unsetField(Object field, Object input)
      Removes a specified field in a document.
      Parameters:
      field - the expression yielding the field name
      input - Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined.
      Returns:
      the new expression
      Since:
      2.3
      Since server release
      5.0
      MongoDB documentation
      Aggregration Expression: $unsetField