updateData()

Update document data field contents.

Signature

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

Description

The updateData() method updates the document data field with the object fields and returns the updated document. During the update, object fields are copied to the document data field, 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 data fields.

Examples

  1. Create a document with a data field:

    Books.createData({
      name: "Then and Now",
      author: "W. Somerset Maugham",
      data: "007571098 "
    })
    {
      id: "365648872630911009",
      coll: Books,
      ts: Time("2023-05-24T22:53:08.660Z"),
      name: "Then and Now",
      author: "W. Somerset Maugham",
      data: {
        data: "007571098 "
      }
    }
  2. Update the data field:

    Books.byId("365648872630911009")!.updateData({
      update: "fixed typo",
      data: "007571098"
    })
    {
      id: "365648872630911009",
      coll: Books,
      ts: Time("2023-05-24T23:01:49.870Z"),
      name: "Then and Now",
      author: "W. Somerset Maugham",
      data: {
        data: "007571098",
        update: "fixed typo"
      }
    }

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!