Factory function that creates an instance of a statement to modify
one or more documents in a collection.
- Mixes In:
- See:
Methods
-
arrayAppend(docPath, exprOrLiteral)
-
Registers an update operation that appends a given element to on array field on all documents that match the criteria. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Description docPath
DocPath The full path of the document field to update. exprOrLiteral
ExprOrLiteral A new value to assign to the field. Returns:
The instance of the statement itself following a fluent API convention. -
arrayDelete(docPath)
-
Registers an update operation that deletes an array field from all documents that match the criteria. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Description docPath
DocPath The full path of the document field to update. - Deprecated:
-
- since version 8.0.12. Will be removed in future versions. Use CollectionModify.unset() instead.
Returns:
The Instance of the statement itself following a fluent API convention. -
arrayInsert(docPath, exprOrLiteral)
-
Registers an update operation that inserts an element at given index of an array field on all documents that match the criteria. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Description docPath
DocPath The full path of the document field (including the array index) to update. exprOrLiteral
ExprOrLiteral A new value to insert into the array at the given index. Returns:
The instance of the statement itself following a fluent API convention. -
execute()
-
Executes the statement in the database that modifies all documents in the collection that match the given criteria.
Returns:
APromise
that resolves to an object containing the details reported by the server.- Type
- Promise.<module:Result>
-
patch(documentOrJSON)
-
Registers an update operation that updates multiple fields of all documents that match the criteria. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Description documentOrJSON
DocumentOrJSON Object containing the fields and corresponding values to create, remove or update (diff) in each document. Returns:
The instance of the statement itself following a fluent API convention. -
set(docPath, exprOrLiteral)
-
Registers an update operation that updates a single field of all documents that match the criteria. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Description docPath
DocPath The full path of the document field to update. exprOrLiteral
ExprOrLiteral A new value to assign to the field. Returns:
An instance of the statement itself following a fluent API convention. -
unset(docPaths)
-
Registers an update operation that removes one or more fields from all documents that match the criteria. This method does not cause the statement to be executed but changes the statement boundaries, which means that if it has been prepared before, it needs to be re-prepared.
Parameters:
Name Type Argument Description docPaths
DocPaths <repeatable>
One ore more paths of fields to remove. Returns:
The instance of the statement itself following a fluent API convention.