This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Inserts or updates an item in a collection.
The save()
method returns a Promise that resolves to the inserted or
updated item after it has been added or updated in the specified
collection. The Promise is rejected if the current user does not have
the necessary permissions for the collection.
The save()
method inserts or updates the specified item, depending on
whether it already exists in the collection. It compares the _id
property
value 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,
save()
uses update()
to update the item in the collection, triggering
the beforeUpdate()
and afterUpdate()
hooks if they have been defined.
If none of the items in the collection contain that _id
value, the
specified item does not have an _id
property, or if the specified item's
id property is undefined
, save()
uses insert()
to add the specified
item to the collection. This triggers the beforeInsert()
and
afterInsert()
hooks if they have been defined.
When saving an item to 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.
Notes:
_id
property value is set to null or an empty string, an error is thrown.save()
method does not support multi-reference fields. For multi-reference fields, use insertReference()
or replaceReferences()
.save()
fails and issues an error.
ID of the collection item belongs to.
Data item to save.
Options to use when processing this operation.