Class MutateInSpec
- Direct Known Subclasses:
ArrayAddUnique
,ArrayAppend
,ArrayInsert
,ArrayPrepend
,Increment
,Insert
,Remove
,Replace
,ReplaceBodyWithXattr
,Upsert
Note that each spec only specifies a portion of a document. Whether the whole document is to be upserted or
inserted is controlled by MutateInOptions.storeSemantics(StoreSemantics)
on the outer options block.
Some operations allow to specify an empty path ("") which means that the root document level is used (so it will be applied to the full document). By nature it makes sense to only use such a command in isolation, but it can be combined with xattr (extended attributes, a document metadata section) operations as well.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ArrayAddUnique
arrayAddUnique
(String path, Object value) Creates a command with the intent of inserting a value into an existing JSON array, but only if the value is not already contained in the array (by way of string comparison).static ArrayAppend
arrayAppend
(String path, List<?> values) Creates a command with the intention of appending a value to an existing JSON array.static ArrayInsert
arrayInsert
(String path, List<?> values) Creates a command with the intention of inserting a value into an existing JSON array.static ArrayPrepend
arrayPrepend
(String path, List<?> values) Creates a command with the intention of prepending a value to an existing JSON array.static Increment
Creates a command with the intent of decrementing a numerical field in a JSON object.static Increment
Creates a command with the intent of incrementing a numerical field in a JSON object.static Insert
Creates a command with the intention of inserting a new value in a JSON object.static Remove
Creates a command with the intention of removing an existing value in a JSON object.static Replace
Creates a spec with the intention of replacing an existing value in a JSON document.abstract CoreSubdocMutateCommand
toCore
(JsonSerializer serializer) Internal operation called from the encoding side that encodes the spec into its internal representation.static Upsert
Creates a command with the intention of upserting a value in a JSON object.
-
Constructor Details
-
MutateInSpec
public MutateInSpec()
-
-
Method Details
-
toCore
Internal operation called from the encoding side that encodes the spec into its internal representation.- Parameters:
serializer
- the serializer that should be used.- Returns:
- the encoded command.
-
replace
Creates a spec with the intention of replacing an existing value in a JSON document.If the path is empty (""), then the value will be used for the document's full body. Will error if the last element of the path does not exist.
- Parameters:
path
- the path identifying where to replace the value.value
- the value to replace with.- Returns:
- the created
MutateInSpec
.
-
insert
Creates a command with the intention of inserting a new value in a JSON object.Will error if the last element of the path already exists.
- Parameters:
path
- the path identifying where to insert the value.value
- the value to insert- Returns:
- the created
MutateInSpec
.
-
remove
Creates a command with the intention of removing an existing value in a JSON object.Will error if the path does not exist.
- Parameters:
path
- the path identifying what to remove.- Returns:
- the created
MutateInSpec
.
-
upsert
Creates a command with the intention of upserting a value in a JSON object.That is, the value will be replaced if the path already exists, or inserted if not.
- Parameters:
path
- the path identifying where to upsert the value.value
- the value to upsert.- Returns:
- the created
MutateInSpec
.
-
arrayAppend
Creates a command with the intention of appending a value to an existing JSON array.Will error if the last element of the path does not exist or is not an array.
- Parameters:
path
- the path identifying an array to which to append the value.values
- the value(s) to append.- Returns:
- the created
MutateInSpec
.
-
arrayPrepend
Creates a command with the intention of prepending a value to an existing JSON array.Will error if the last element of the path does not exist or is not an array.
- Parameters:
path
- the path identifying an array to which to append the value.values
- the value(s) to prepend.- Returns:
- the created
MutateInSpec
.
-
arrayInsert
Creates a command with the intention of inserting a value into an existing JSON array.Will error if the last element of the path does not exist or is not an array.
- Parameters:
path
- the path identifying an array to which to append the value, and an index. E.g. "foo.bar[3]"values
- the value(s) to insert.- Returns:
- the created
MutateInSpec
.
-
arrayAddUnique
Creates a command with the intent of inserting a value into an existing JSON array, but only if the value is not already contained in the array (by way of string comparison).Will error if the last element of the path does not exist or is not an array.
- Parameters:
path
- the path identifying an array to which to append the value. For example: "foo.bar"value
- the value to insert.- Returns:
- the created
MutateInSpec
.
-
increment
Creates a command with the intent of incrementing a numerical field in a JSON object. If the field does not exist then it is created and takes the value of `delta`.- Parameters:
path
- the path identifying a numerical field to adjust or create.delta
- the value to increment the field by.- Returns:
- the created
MutateInSpec
.
-
decrement
Creates a command with the intent of decrementing a numerical field in a JSON object. If the field does not exist then it is created and takes the value of `delta` * -1.- Parameters:
path
- the path identifying a numerical field to adjust or create.delta
- the value to increment the field by.- Returns:
- the created
MutateInSpec
.
-