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
      MongoDB documentation
      Aggregration Expression: $getField
      Since server release
      5.0
    • 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
      MongoDB documentation
      Aggregration Expression: $getField
      Since server release
      5.0
    • rand

      public static Expression rand()
      Returns a random float between 0 and 1.
      Returns:
      the filter
      Since:
      2.2
      MongoDB documentation
      Aggregration Expression: $rand
      Since server release
      4.4.2
    • 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
      MongoDB documentation
      Aggregration Expression: $sampleRate
      Since server release
      4.4.2
    • 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
      MongoDB documentation
      Aggregration Expression: $setField
      Since server release
      5.0
    • 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
      MongoDB documentation
      Aggregration Expression: $unsetField
      Since server release
      5.0