This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Updates an item in a collection.
The update()
method returns a Promise that resolves to the updated item from
the specified collection. The Promise is rejected if the current user does not
have update permissions for the collection.
Calling the update()
method triggers the beforeUpdate()
and afterUpdate()
hooks if they have been defined.
The update()
method compares the _id
property of the specified item
with the _id
property values of the items in the specified collection. If
an item in the collection has that _id
value, update()
replaces the
item's property values with the ones in the specified item. If the existing
item had properties with values and those properties were not included in
the specified item, the values in those properties are lost. The item's
_updatedDate
property is also updated to the current date.
Any valid JavaScript object can be used as a property value. The update()
method maintains the structure of the specified object. For example,
objects that contain nested objects, arrays, or arrays with nested objects
are all added to the collection as defined.
When updating an item in a collection that has a reference field, set the
value of the reference field to the referenced item's _id
value or the
entire referenced item object.
The maximum size of an item that you can update in a collection is 500kb.
Notes:
_id
property that already exists in the collection.update()
method does not support multi-reference fields. For multi-reference fields, use replaceReferences()
or insertReference()
.update()
fails and issues an error.
ID of the collection item belongs to.
Data item to update.
Options to use when processing this operation.