replace()

Replace all document fields.

Signature

replace(object: { ttl: Time | Null, *: Any }): <Document>

Description

The replace() method replaces all fields with object, except for the immutable metadata fields id, coll, and ts. Fields not present in object, except immutable metadata fields, are removed from the document.

Parameters

Parameter Type Required Description

object

Object

Yes

Object with the replacement document fields.

object fields

Name Type Required Description

ttl

Time

Timestamp indicating when to remove the document. When the document is removed, it ceases to exist and temporal queries can’t recover the document.
Default = null, which persists the document indefinitely.

Return value

Type Description

Document

Document with replaced fields.

Examples

Create and replace a document:

Character.create({
  name: "Red Shirt",
  phaser: "stun",
  termination: "35 seconds after teleport",
})!.replace({
  name: "Princess Eilonwy",
  age: 12,
  attributes: ["brave", "cynical", "talkative"],
})
{
  id: "346366070088532480",
  coll: Character,
  ts: Time("2022-10-24T02:41:15.130Z"),
  name: "Princess Eilonwy",
  age: 12,
  attributes: [
    "brave",
    "cynical",
    "talkative"
  ]
}

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!