update()

Update an key.

Signature

update(object: {*: Any}): <Key>

Description

The update() method updates the document with the object fields and returns the updated document. Use the update() method to rename a key or update its user-defined metadata. During the update, fields from object are copied to the document, creating new fields or updating existing fields.

The operation is similar to a merge. Only the fields included in object are updated. All other document fields aren’t updated. Fields with nested objects in object are merged with the identically named nested object in the document.

To remove a document field, set its value in object to null.

Parameters

Parameter Type Required Description

object

Object

Yes

Object with the updated document fields.

Return value

Type Description

Document

Document with updated fields.

Examples

Key.byId('369964891183775778')!.update({
      data: {
        name: "coffee-admin"
      }
})
{
  id: "369964891183775778",
  coll: Key,
  ts: Time("2023-07-11T14:17:49.890Z"),
  data: {
    name: "coffee-admin"
  },
  role: "admin"
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!