MutateInBuilder
class MutateInBuilder (View source)
A builder for subdocument mutations. In order to perform the final set of operations, use the execute() method.
Instances of this builder should be obtained through \Couchbase\Bucket->mutateIn()
Constants
FULLDOC_REPLACE |
|
FULLDOC_UPSERT |
|
FULLDOC_INSERT |
|
Methods
Insert a fragment provided the last element of the path doesn't exists.
Select mode for new full-document operations.
Insert a fragment, replacing the old value if the path exists.
Replace an existing value by the given fragment
Remove an entry in a JSON document.
Prepend to an existing array, pushing the value to the front/first position in the array.
Prepend multiple values at once in an existing array.
Append to an existing array, pushing the value to the back/last position in the array.
Append multiple values at once in an existing array.
Insert into an existing array at a specific position
Insert multiple values at once in an existing array at a specified position.
Insert a value in an existing array only if the value isn't already contained in the array (by way of string comparison).
Increment/decrement a numerical fragment in a JSON document.
Change the expiry of the enclosing document as part of the mutation.
Perform several mutation operations inside a single existing JSON document.
Details
MutateInBuilder
insert(string $path, mixed $value, array|bool $options = [])
Insert a fragment provided the last element of the path doesn't exists.
modeDocument(int $mode)
Select mode for new full-document operations.
It defines behaviour of MutateInBuilder#upsert() method. The $mode could take one of three modes:
- FULLDOC_REPLACE: complain when document does not exist
- FULLDOC_INSERT: complain when document does exist
- FULLDOC_UPSERT: unconditionally set value for the document
MutateInBuilder
upsert(string $path, mixed $value, array|bool $options = [])
Insert a fragment, replacing the old value if the path exists.
When only one argument supplied, the library will handle it as full-document upsert, and treat this argument as value. See MutateInBuilder#modeDocument()
MutateInBuilder
replace(string $path, mixed $value, array $options = [])
Replace an existing value by the given fragment
MutateInBuilder
remove(string $path, array $options = [])
Remove an entry in a JSON document.
Scalar, array element, dictionary entry, whole array or dictionary, depending on the path.
MutateInBuilder
arrayPrepend(string $path, mixed $value, array|bool $options = [])
Prepend to an existing array, pushing the value to the front/first position in the array.
MutateInBuilder
arrayPrependAll(string $path, array $values, array|bool $options = [])
Prepend multiple values at once in an existing array.
Push all values in the collection's iteration order to the front/start of the array. For example given an array [A, B, C], prepending the values X and Y yields [X, Y, A, B, C] and not [[X, Y], A, B, C].
MutateInBuilder
arrayAppend(string $path, mixed $value, array|bool $options = [])
Append to an existing array, pushing the value to the back/last position in the array.
MutateInBuilder
arrayAppendAll(string $path, array $values, array|bool $options = [])
Append multiple values at once in an existing array.
Push all values in the collection's iteration order to the back/end of the array. For example given an array [A, B, C], appending the values X and Y yields [A, B, C, X, Y] and not [A, B, C, [X, Y]].
MutateInBuilder
arrayInsert(string $path, mixed $value, array $options = [])
Insert into an existing array at a specific position
Position denoted in the path, eg. "sub.array[2]".
MutateInBuilder
arrayInsertAll(string $path, array $values, array $options = [])
Insert multiple values at once in an existing array at a specified position.
Position denoted in the path, eg. "sub.array[2]"), inserting all values in the collection's iteration order at the given position and shifting existing values beyond the position by the number of elements in the collection.
For example given an array [A, B, C], inserting the values X and Y at position 1 yields [A, B, X, Y, C] and not [A, B, [X, Y], C].
MutateInBuilder
arrayAddUnique(string $path, mixed $value, array|bool $options = [])
Insert a value in an existing array only if the value isn't already contained in the array (by way of string comparison).
MutateInBuilder
counter(string $path, int $delta, array|bool $options = [])
Increment/decrement a numerical fragment in a JSON document.
If the value (last element of the path) doesn't exist the counter is created and takes the value of the delta.
MutateInBuilder
withExpiry(mixed $expiry)
Change the expiry of the enclosing document as part of the mutation.
DocumentFragment
execute()
Perform several mutation operations inside a single existing JSON document.