SurrealDB Docs Logo

Enter a search query

.Merge[T](what, data)

Modifies all records in a table, or a specific record.

Method Syntax
db.Merge[T](what, data)
Note

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

Arguments

ArgumentsDescription
thing required

The table name or the specific RecordId to merge.

data optional

The data with which to modify the records.

Example usage

Merging data within a single record
type PersonMerge struct { ID models.RecordID `json:"id"` Settings struct { Active bool `json:"active"` Marketing bool `json:"marketing"` } `json:"settings"` } // Define the partial update data using a struct mergeData := PersonMerge{ ID: models.NewRecordID("person", "tobie"), Settings: struct { Active bool `json:"active"` Marketing bool `json:"marketing"` }{ Active: true, Marketing: false, }, } // Perform the merge operation updatedPerson, err := surrealdb.Merge[Person, models.RecordID](db, mergeData.ID, mergeData) if err != nil { panic(err) } fmt.Printf("Merged person record with struct: %+v\n", updatedPerson)

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install