public final class Updates
extends java.lang.Object
collection.updateOne(eq("x", 1), set("x", 2));
Modifier and Type | Method and Description |
---|---|
static <TItem> Bson |
addEachToSet(java.lang.String fieldName,
java.util.List<TItem> values)
Creates an update that adds each of the given values to the array value of the field with the given name, unless the value is
already present, in which case it does nothing
|
static <TItem> Bson |
addToSet(java.lang.String fieldName,
TItem value)
Creates an update that adds the given value to the array value of the field with the given name, unless the value is
already present, in which case it does nothing
|
static Bson |
bitwiseAnd(java.lang.String fieldName,
int value)
Creates an update that performs a bitwise and between the given integer value and the integral value of the field with the given
name.
|
static Bson |
bitwiseAnd(java.lang.String fieldName,
long value)
Creates an update that performs a bitwise and between the given long value and the integral value of the field with the given name.
|
static Bson |
bitwiseOr(java.lang.String fieldName,
int value)
Creates an update that performs a bitwise or between the given integer value and the integral value of the field with the given
name.
|
static Bson |
bitwiseOr(java.lang.String fieldName,
long value)
Creates an update that performs a bitwise or between the given long value and the integral value of the field with the given name.
|
static Bson |
bitwiseXor(java.lang.String fieldName,
int value)
Creates an update that performs a bitwise xor between the given integer value and the integral value of the field with the given
name.
|
static Bson |
bitwiseXor(java.lang.String fieldName,
long value)
Creates an update that performs a bitwise xor between the given long value and the integral value of the field with the given name.
|
static Bson |
combine(Bson... updates)
Combine a list of updates into a single update.
|
static Bson |
combine(java.util.List<? extends Bson> updates)
Combine a list of updates into a single update.
|
static Bson |
currentDate(java.lang.String fieldName)
Creates an update that sets the value of the field to the current date as a BSON date.
|
static Bson |
currentTimestamp(java.lang.String fieldName)
Creates an update that sets the value of the field to the current date as a BSON timestamp.
|
static Bson |
inc(java.lang.String fieldName,
java.lang.Number number)
Creates an update that increments the value of the field with the given name by the given value.
|
static <TItem> Bson |
max(java.lang.String fieldName,
TItem value)
Creates an update that sets the value of the field to the given value if the given value is greater than the current value of the
field.
|
static <TItem> Bson |
min(java.lang.String fieldName,
TItem value)
Creates an update that sets the value of the field to the given value if the given value is less than the current value of the
field.
|
static Bson |
mul(java.lang.String fieldName,
java.lang.Number number)
Creates an update that multiplies the value of the field with the given name by the given number.
|
static Bson |
popFirst(java.lang.String fieldName)
Creates an update that pops the first element of an array that is the value of the field with the given name.
|
static Bson |
popLast(java.lang.String fieldName)
Creates an update that pops the last element of an array that is the value of the field with the given name.
|
static <TItem> Bson |
pull(java.lang.String fieldName,
TItem value)
Creates an update that removes all instances of the given value from the array value of the field with the given name.
|
static <TItem> Bson |
pullAll(java.lang.String fieldName,
java.util.List<TItem> values)
Creates an update that removes all instances of the given values from the array value of the field with the given name.
|
static Bson |
pullByFilter(Bson filter)
Creates an update that removes from an array all elements that match the given filter.
|
static <TItem> Bson |
push(java.lang.String fieldName,
TItem value)
Creates an update that adds the given value to the array value of the field with the given name.
|
static <TItem> Bson |
pushEach(java.lang.String fieldName,
java.util.List<TItem> values)
Creates an update that adds each of the given values to the array value of the field with the given name.
|
static <TItem> Bson |
pushEach(java.lang.String fieldName,
java.util.List<TItem> values,
PushOptions options)
Creates an update that adds each of the given values to the array value of the field with the given name, applying the given
options for positioning the pushed values, and then slicing and/or sorting the array.
|
static Bson |
rename(java.lang.String fieldName,
java.lang.String newFieldName)
Creates an update that renames a field.
|
static <TItem> Bson |
set(java.lang.String fieldName,
TItem value)
Creates an update that sets the value of the field with the given name to the given value.
|
static <TItem> Bson |
setOnInsert(java.lang.String fieldName,
TItem value)
Creates an update that sets the value of the field with the given name to the given value, but only if the update is an upsert that
results in an insert of a document.
|
static Bson |
unset(java.lang.String fieldName)
Creates an update that deletes the field with the given name.
|
public static Bson combine(Bson... updates)
updates
- the list of updatespublic static Bson combine(java.util.List<? extends Bson> updates)
updates
- the list of updatespublic static <TItem> Bson set(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valuepublic static Bson unset(java.lang.String fieldName)
fieldName
- the non-null field namepublic static <TItem> Bson setOnInsert(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valueUpdateOptions.upsert(boolean)
public static Bson rename(java.lang.String fieldName, java.lang.String newFieldName)
fieldName
- the non-null field namenewFieldName
- the non-null new field namepublic static Bson inc(java.lang.String fieldName, java.lang.Number number)
fieldName
- the non-null field namenumber
- the valuepublic static Bson mul(java.lang.String fieldName, java.lang.Number number)
fieldName
- the non-null field namenumber
- the non-null numberpublic static <TItem> Bson min(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valuepublic static <TItem> Bson max(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valuepublic static Bson currentDate(java.lang.String fieldName)
fieldName
- the non-null field namepublic static Bson currentTimestamp(java.lang.String fieldName)
fieldName
- the non-null field namepublic static <TItem> Bson addToSet(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valuepublic static <TItem> Bson addEachToSet(java.lang.String fieldName, java.util.List<TItem> values)
TItem
- the value typefieldName
- the non-null field namevalues
- the valuespublic static <TItem> Bson push(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valuepublic static <TItem> Bson pushEach(java.lang.String fieldName, java.util.List<TItem> values)
TItem
- the value typefieldName
- the non-null field namevalues
- the valuespublic static <TItem> Bson pushEach(java.lang.String fieldName, java.util.List<TItem> values, PushOptions options)
TItem
- the value typefieldName
- the non-null field namevalues
- the valuesoptions
- the non-null push optionspublic static <TItem> Bson pull(java.lang.String fieldName, TItem value)
TItem
- the value typefieldName
- the non-null field namevalue
- the valuepublic static Bson pullByFilter(Bson filter)
filter
- the query filterpublic static <TItem> Bson pullAll(java.lang.String fieldName, java.util.List<TItem> values)
TItem
- the value typefieldName
- the non-null field namevalues
- the valuespublic static Bson popFirst(java.lang.String fieldName)
fieldName
- the non-null field namepublic static Bson popLast(java.lang.String fieldName)
fieldName
- the non-null field namepublic static Bson bitwiseAnd(java.lang.String fieldName, int value)
fieldName
- the field namevalue
- the valuepublic static Bson bitwiseAnd(java.lang.String fieldName, long value)
fieldName
- the field namevalue
- the valuepublic static Bson bitwiseOr(java.lang.String fieldName, int value)
fieldName
- the field namevalue
- the valuepublic static Bson bitwiseOr(java.lang.String fieldName, long value)
fieldName
- the field namevalue
- the valuepublic static Bson bitwiseXor(java.lang.String fieldName, int value)
fieldName
- the field namevalue
- the valuepublic static Bson bitwiseXor(java.lang.String fieldName, long value)
fieldName
- the field namevalue
- the value