Class Miscellaneous


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static dev.morphia.aggregation.expressions.impls.Expression getField​(dev.morphia.aggregation.expressions.impls.Expression field)
      Returns the value of a specified field from a document.
      static dev.morphia.aggregation.expressions.impls.Expression getField​(String field)
      Returns the value of a specified field from a document.
      static dev.morphia.aggregation.expressions.impls.Expression rand()
      Returns a random float between 0 and 1.
      static Filter sampleRate​(double rate)
      Matches a random selection of input documents.
      static dev.morphia.aggregation.expressions.impls.Expression setField​(dev.morphia.aggregation.expressions.impls.Expression field, Object input, dev.morphia.aggregation.expressions.impls.Expression value)
      Adds, updates, or removes a specified field in a document.
      static dev.morphia.aggregation.expressions.impls.Expression setField​(String field, Object input, dev.morphia.aggregation.expressions.impls.Expression value)
      Adds, updates, or removes a specified field in a document.
      static dev.morphia.aggregation.expressions.impls.Expression unsetField​(dev.morphia.aggregation.expressions.impls.Expression field, Object input)
      Removes a specified field in a document.
      static dev.morphia.aggregation.expressions.impls.Expression unsetField​(String field, Object input)
      Removes a specified field in a document.
    • Method Detail

      • getField

        public static dev.morphia.aggregation.expressions.impls.Expression 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 dev.morphia.aggregation.expressions.impls.Expression getField​(dev.morphia.aggregation.expressions.impls.Expression 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 dev.morphia.aggregation.expressions.impls.Expression rand()
        Returns a random float between 0 and 1.
        Returns:
        the filter
        Since:
        2.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
        MongoDB documentation
        Aggregration Expression: $sampleRate
      • setField

        public static dev.morphia.aggregation.expressions.impls.Expression setField​(String field,
                                                                                    Object input,
                                                                                    dev.morphia.aggregation.expressions.impls.Expression 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
      • setField

        public static dev.morphia.aggregation.expressions.impls.Expression setField​(dev.morphia.aggregation.expressions.impls.Expression field,
                                                                                    Object input,
                                                                                    dev.morphia.aggregation.expressions.impls.Expression 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 dev.morphia.aggregation.expressions.impls.Expression unsetField​(String field,
                                                                                      Object input)
        Removes a specified field in a document.
        Parameters:
        field - 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
      • unsetField

        public static dev.morphia.aggregation.expressions.impls.Expression unsetField​(dev.morphia.aggregation.expressions.impls.Expression 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