Tutorial: Building with CleaveDB
Updating Single Fields
In many application workflows, you only need to modify one property of a record—such as updating an account status, incrementing an inventory level, or setting a user preference. The simplest form of CHANGE pairs an identified document with a single SET assignment.
Update a field on an identified document
Specify the target bucket, the document ID, and the field you wish to update using SET:
CHANGE users "jane" SET status = "active"CleaveDB locates the document with ID "jane" in the users bucket, updates the status property to "active", and persists the update immediately. Any other fields in Jane's record—such as email, name, or metadata—remain completely unchanged.
Updating numerical fields
Numerical values such as stock counts, prices, or counters can be set directly:
CHANGE products "prod_402" SET stock = 42The new numeric value replaces the existing field value in place, triggering index updates if stock has an associated B+Tree index.
Update nested single fields
You can reach into nested JSON objects using dot-notation:
CHANGE users "jane" SET profile.preferences.theme = "dark"This navigates down Jane's profile.preferences object and updates only the theme property, keeping sibling properties like language or notifications intact.
Conditional single-field updates
You can also apply single-field updates across multiple documents matching a filter using WHERE:
CHANGE orders WHERE status = "pending" SET status = "processing"Every order document in the bucket where status equals "pending" is updated to "processing" in an atomic transaction.
