public abstract class MutateInSpec extends Object
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 and Description |
---|
MutateInSpec() |
Modifier and Type | Method and Description |
---|---|
static 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 |
decrement(String path,
long delta)
Creates a command with the intent of decrementing a numerical field in a JSON object.
|
abstract SubdocMutateRequest.Command |
encode(JsonSerializer serializer,
int originalIndex)
Internal operation called from the encoding side that encodes the spec into its internal representation.
|
static Increment |
increment(String path,
long delta)
Creates a command with the intent of incrementing a numerical field in a JSON object.
|
static Insert |
insert(String path,
Object value)
Creates a command with the intention of inserting a new value in a JSON object.
|
static Remove |
remove(String path)
Creates a command with the intention of removing an existing value in a JSON object.
|
static Replace |
replace(String path,
Object value)
Creates a spec with the intention of replacing an existing value in a JSON document.
|
static Upsert |
upsert(String path,
Object value)
Creates a command with the intention of upserting a value in a JSON object.
|
@Stability.Internal public abstract SubdocMutateRequest.Command encode(JsonSerializer serializer, int originalIndex)
serializer
- the serializer that should be used.originalIndex
- the original index of the command.public static Replace replace(String path, Object value)
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.
path
- the path identifying where to replace the value.value
- the value to replace with.MutateInSpec
.public static Insert insert(String path, Object value)
Will error if the last element of the path already exists.
path
- the path identifying where to insert the value.value
- the value to insertMutateInSpec
.public static Remove remove(String path)
Will error if the path does not exist.
path
- the path identifying what to remove.MutateInSpec
.public static Upsert upsert(String path, Object value)
That is, the value will be replaced if the path already exists, or inserted if not.
path
- the path identifying where to upsert the value.value
- the value to upsert.MutateInSpec
.public static ArrayAppend arrayAppend(String path, List<?> values)
Will error if the last element of the path does not exist or is not an array.
path
- the path identifying an array to which to append the value.values
- the value(s) to append.MutateInSpec
.public static ArrayPrepend arrayPrepend(String path, List<?> values)
Will error if the last element of the path does not exist or is not an array.
path
- the path identifying an array to which to append the value.values
- the value(s) to prepend.MutateInSpec
.public static ArrayInsert arrayInsert(String path, List<?> values)
Will error if the last element of the path does not exist or is not an array.
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.MutateInSpec
.public static ArrayAddUnique arrayAddUnique(String path, Object value)
Will error if the last element of the path does not exist or is not an array.
path
- the path identifying an array to which to append the value, and an index. E.g. "foo.bar[3]"value
- the value to insert.MutateInSpec
.public static Increment increment(String path, long delta)
path
- the path identifying a numerical field to adjust or create.delta
- the value to increment the field by.MutateInSpec
.public static Increment decrement(String path, long delta)
path
- the path identifying a numerical field to adjust or create.delta
- the value to increment the field by.MutateInSpec
.Copyright © 2021 Couchbase, Inc.. All rights reserved.