Update

Use update() to modify an existing document by its ID. Only the fields you pass will be updated — the rest stay untouched.

Maps to PATCH /:collection/docs/:id. The response returns the updated document.

✏️ update()

await db.users.update("user_gilfoyle", {
  name: "Bertram Gilfoyle",
  isAdmin: true,
});

This updates just the name and isAdmin fields of the document with _id: "user_gilfoyle".

Increment / Decrement

The API also supports numeric delta operations in updates:

await db.users.update("user_gilfoyle", {
  loginCount: { increment: 1 },
});
await db.users.update("user_gilfoyle", {
  credits: { decrement: 5 },
});

Behavior

  • Partial update: You do not need to pass all fields.
  • Schema validated: The new fields are still validated against the schema.
  • updatedAt is automatically updated for you.
  • Missing document IDs return 404 and surface as SDK errors.