Tutorial: Building with CleaveDB
Updating Multiple Fields
When an event in your application requires several attributes to change simultaneously—such as upgrading a subscriber's plan, updating contact information, or marking an item as shipped with tracking info—you can update multiple fields in a single CHANGE statement.
Comma-separated field assignments
Chain multiple assignments after SET separated by commas:
CHANGE users "jane" SET status = "verified", plan = "pro", updated_at = 1712750400In this example, CleaveDB updates Jane's status, plan, and updated_at timestamp together in a single atomic operation. Other fields remain untouched.
Mixing top-level and nested fields
You can mutate top-level fields and deep nested paths in the same statement:
CHANGE users "jane" SET email = "jane@cleavedb.io", profile.bio = "Database Architect", profile.verified = trueThis allows complex document evolution without needing to re-fetch the document, edit the JSON client-side, and push the entire document back.
Batch updating multiple fields with WHERE
When migrating data or updating categories across a bucket, combine multiple field updates with a filter:
CHANGE subscriptions WHERE tier = "legacy" SET tier = "starter", auto_renew = false, migration_status = "completed"Every record matching the filter is modified with all three values, maintaining consistency across the entire matched cohort.
