Class UpdateOperators

    • Method Detail

      • addToSet

        public static AddToSetOperator addToSet​(String field,
                                                Object value)
        The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array.
        Parameters:
        field - the field to updated
        value - the value to add
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $addToSet
      • addToSet

        public static AddToSetOperator addToSet​(String field,
                                                List<?> values)
        The $addToSet operator adds a value to an array unless the value is already present, in which case $addToSet does nothing to that array. By default, this operator will use $each to add each element in the given list to the stored array in the document.
        Parameters:
        field - the field to updated
        values - the values to add
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $addToSet
        Update Operator: $each
      • and

        public static UpdateOperator and​(String field,
                                         int value)
        The $bit operator performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations.
        Parameters:
        field - the field to update
        value - the value to use for the update
        Returns:
        the update operator
        See Also:
        or(String, int), xor(String, int)
        MongoDB documentation
        Update Operator: $bit
      • currentDate

        public static CurrentDateOperator currentDate​(String field)
        The $currentDate operator sets the value of a field to the current date, either as a Date or a timestamp. The default type is Date.
        Parameters:
        field - the field to set
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $currentDate
      • dec

        public static UpdateOperator dec​(String field)
        Decrements the value of the field by one.
        Parameters:
        field - the field to decrement
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $dec
      • dec

        public static UpdateOperator dec​(String field,
                                         Number value)
        Decrements the value of the field by the specified amount.
        Parameters:
        field - the field to decrement
        value - the number to decrement by
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $dec
      • inc

        public static UpdateOperator inc​(String field)
        Increments the value of the field by one.
        Parameters:
        field - the field to increment
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $inc
      • inc

        public static UpdateOperator inc​(String field,
                                         Number value)
        Increments the value of the field by the specified amount.
        Parameters:
        field - the field to increment
        value - the number to increment by
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $inc
      • max

        public static UpdateOperator max​(String field,
                                         Number value)
        Only updates the field if the specified value is greater than the existing field value.
        Parameters:
        field - the field to update
        value - the max value to apply
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $max
      • max

        public static UpdateOperator max​(String field,
                                         Temporal value)
        Only updates the field if the specified value is greater than the existing field value.
        Parameters:
        field - the field to update
        value - the max value to apply
        Returns:
        the update operator
        Since:
        2.2
        MongoDB documentation
        Update Operator: $max
      • max

        public static UpdateOperator max​(String field,
                                         Date value)
        Only updates the field if the specified value is greater than the existing field value.
        Parameters:
        field - the field to update
        value - the max value to apply
        Returns:
        the update operator
        Since:
        2.2
        MongoDB documentation
        Update Operator: $max
      • min

        public static UpdateOperator min​(String field,
                                         Number value)
        Only updates the field if the specified value is less than the existing field value.
        Parameters:
        field - the field to update
        value - the min value to apply
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $min
      • min

        public static UpdateOperator min​(String field,
                                         Temporal value)
        Only updates the field if the specified value is less than the existing field value.
        Parameters:
        field - the field to update
        value - the min value to apply
        Returns:
        the update operator
        Since:
        2.2
        MongoDB documentation
        Update Operator: $min
      • min

        public static UpdateOperator min​(String field,
                                         Date value)
        Only updates the field if the specified value is less than the existing field value.
        Parameters:
        field - the field to update
        value - the min value to apply
        Returns:
        the update operator
        Since:
        2.2
        MongoDB documentation
        Update Operator: $min
      • mul

        public static UpdateOperator mul​(String field,
                                         Number value)
        Multiplies the value of the field by the specified amount.
        Parameters:
        field - the field to multiply
        value - the number to multiply by
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $mul
      • or

        public static UpdateOperator or​(String field,
                                        int value)
        The $bit operator performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations.
        Parameters:
        field - the field to update
        value - the value to use for the update
        Returns:
        the update operator
        See Also:
        and(String, int), xor(String, int)
        MongoDB documentation
        Update Operator: $bit
      • pop

        public static PopOperator pop​(String field)
        The $pop operator removes the first or last element of an array. This operation can remove the first of the last value but defaults to removing the last.
        Parameters:
        field - the field to update
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $pop
      • pull

        public static UpdateOperator pull​(String field,
                                          Filter filter)
        The $pull operator removes from an existing array all instances of a value or values that match a specified condition.
        Parameters:
        field - the field to update
        filter - the filter to apply
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $pull
      • pullAll

        public static UpdateOperator pullAll​(String field,
                                             List<?> values)
        The $pullAll operator removes all instances of the specified values from an existing array. Unlike the $pull operator that removes elements by specifying a query, $pullAll removes elements that match the listed values.
        Parameters:
        field - the field to update
        values - the values to remove
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $pullAll
      • push

        public static PushOperator push​(String field,
                                        Object value)
        The $push operator appends a specified value to an array.
        Parameters:
        field - the field to update
        value - the value to add
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $push
      • set

        public static UpdateOperator set​(String field,
                                         Object value)
        The $set operator replaces the value of a field with the specified value.
        Parameters:
        field - the field to set
        value - the value to set
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $set
      • set

        public static UpdateOperator set​(Object value)
        The $set operator replaces the value of a field with the specified value.
        Parameters:
        value - the value to set
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $set
      • setOnInsert

        public static UpdateOperator setOnInsert​(Map<String,​Object> values)
        If an update operation with upsert: true results in an insert of a document, then $setOnInsert assigns the specified values to the fields in the document. If the update operation does not result in an insert, $setOnInsert does nothing.
        Parameters:
        values - the fields and their values to insert
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $setOnInsert
      • unset

        public static UpdateOperator unset​(String field)
        The $unset operator deletes a particular field.
        Parameters:
        field - the field to set
        Returns:
        the update operator
        MongoDB documentation
        Update Operator: $unset
      • xor

        public static UpdateOperator xor​(String field,
                                         int value)
        The $bit operator performs a bitwise update of a field. The operator supports bitwise and, bitwise or, and bitwise xor (i.e. exclusive or) operations.
        Parameters:
        field - the field to update
        value - the value to use for the update
        Returns:
        the update operator
        See Also:
        and(String, int), or(String, int)
        MongoDB documentation
        Update Operator: $bit