Class Miscellaneous


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

      • getField

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

        public static Expression getField​(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
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $getField
      • 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 Expression setField​(String field,
                                          Object input,
                                          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
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $setField
      • setField

        public static Expression setField​(Expression field,
                                          Object input,
                                          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
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $setField
      • unsetField

        public static 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
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $unsetField
      • unsetField

        public static Expression unsetField​(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
        Since server release
        5.0
        MongoDB documentation
        Aggregration Expression: $unsetField