This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.
Refines a patch operation to increment the specified field value by the specified parameter.
function incrementField(field: string, by: number): WixDataPatch;
Field whose value is incremented. Nested fields can be specified using dot notation. For example: address.street
.
Value by which to increment the specified field. To decrement, specify a negative value.
import { items } from "@wix/data";
async function incrementField() {
const updatedItem = await items
.patch("BlogPosts", "fb071093-9a40-432d-ae1f-2e5966fecbfa")
.incrementField("viewCount", 1)
.run();
const id = updatedItem._id; // "fb071093-9a40-432d-ae1f-2e5966fecbfa"
const viewCount = updatedItem.viewCount; // 985
}
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.