This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Creates a patch to modify the specified item. Unlike update()
, only the fields specified in the request are modified. Data that isn't explicitly modified remains unchanged.
The patch()
method builds a patch to modify a data item in a specified collection. It returns a WixDataPatch
object that contains the patch definition, which you can further refine by chaining WixDataPatch
methods onto it. These methods allow you to clear, set, and increment field values, as well as add or remove items from array fields. The methods are applied in the order in which they are chained.
Finally, to run the patch, chain run()
as the last method.
If an item is found in the specified collection with the specified ID, that item is patched. If the collection doesn't contain an item with that ID, the request fails.
Calling the patch()
method triggers the beforeUpdate()
and afterUpdate()
hooks, if they have been defined.
Notes:
data._updatedDate
property is updated to the current date and time.function patch(dataCollectionId: string, itemId: string): WixDataPatch;
ID of the collection that contains the item to patch.
ID of the data item to patch.
import { items } from "@wix/data";
async function patch() {
const updatedItem = await items
.patch("BlogPosts", "fb071093-9a40-432d-ae1f-2e5966fecbfa")
.appendToArray("tags", "travel")
.setField("published", true)
.run();
const id = updatedItem._id; // "fb071093-9a40-432d-ae1f-2e5966fecbfa"
const tags = updatedItem.tags; // ["vacations", "travel"]
const published = updatedItem.published; // true
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.