SurrealDB Docs Logo

Enter a search query

.update()

Updates all records in a table, or a specific record, in the database.

Method Syntax
async db.update<T,U>(thing, data)
Note

This function replaces the current document / record data with the specified data.

Arguments

ArgumentsDescription
thing required

The table name or the specific RecordId to update.

data optional

The document / record data to update.

Example usage

type Person = { id: string; name: string; settings: { active: boolean; marketing: boolean; }; }; // Update all records in a table const people = await db.update<Person>('person'); // Update a record with a specific ID const person = await db.update<Person>(new RecordId('person', 'tobie'), { name: 'Tobie', settings: { active: true, marketing: true, }, }); // The content you are updating the record with might differ from the return type const record = await db.update< Person, Pick<Person, 'name'> >(new RecordId('person', 'tobie'), { name: 'Tobie', });

Translated query

This function will run the following query in the database.

UPDATE $thing CONTENT $data;

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install