replace()

Replace an key.

Signature

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

Description

The replace() method replaces keys with the document supplied. This method removes any fields not supplied by the document, with some exceptions. The immutable metadata fields id, coll and ts aren’t removed and can’t be replaced.

The document must include the required fields.

Parameters

Parameter Type Required Description

object

Object

Yes

Object with the replacement document fields.

Return value

Type Description

Document

Document with replaced fields.

Examples

Key.byId('371460335192768546')!.replace({
  role: "humanResources",
  data: {
    foo: "myData"
  }
})
{
  id: "371460335192768546",
  coll: Key,
  ts: Time("2023-07-28T02:25:07.910Z"),
  role: "humanResources",
  data: {
    foo: "myData"
  }
}

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!