replaceData()

Replace document data field contents.

Signature

replaceData(object: {*: any}): <Document>

Description

The replaceData() method replaces all data fields with object. Fields not present in object are removed unless their value is null.

Parameters

Parameter Type Required Description

object

Object

Yes

Object with replacement fields.

Return value

Type Description

Document

Document with replaced data fields.

Examples

Given the following document:

{
  "id": "365648872630911009",
  "coll": "Books",
  "ts": "2023-05-24T23:01:49.870Z",
  "name": "Then and Now",
  "author": "W. Somerset Maugham",
  "data": {
    "data": "007571098",
    "update": "fix typo"
  }
}

 

The following request replaces the data field elements:

Books.byId("365648872630911009")!.replaceData({
  update: "verified"
})
{
  id: "365648872630911009",
  coll: Books,
  ts: Time("2023-05-24T23:03:13.450Z"),
  data: {
    update: "verified"
  }
}

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!