Syntax

selection.update(object) → result

Arguments

List of arguments to provide.
object
object
required
An object containing the fields to update

Optargs

No optional arguments.

Returns

result
object
Information about the operation.

Behavior

  • Updates only the specified fields, leaving other fields unchanged.
  • Can update multiple documents when applied to a selection (filter, getAll, etc.).
  • If a document doesn’t exist, the update operation skips it (no error thrown).

Notes & Caveats

  • Cannot update primary key (id) fields.
  • Use insert defining the same primary key (id) instead of update when you need to replace the entire document.

Example

Update a single document by ID

Update a specific user’s information.
const result = await r
  .table('users')
  .get('user_123')
  .update({
    email: 'newemail@example.com',
    updatedAt: new Date().toISOString()
  })
  .run(client);

console.log(`Updated ${result.updated} document(s)`);

Update multiple documents with filter

Update all users from a specific city.
const result = await r
  .table('users')
  .filter((doc) => doc.field('address.city').eq('San Francisco'))
  .update({
    timezone: 'America/Los_Angeles',
    updatedAt: new Date().toISOString()
  })
  .run(client);
  • get - Get a document by primary key
  • getAll - Get multiple documents
  • filter - Filter documents for updates
  • insert - Insert new documents
  • delete - Delete documents

Found a typo? Or maybe a broken link? RuloDB is open-source, help us fix it!