createData()

Create a document in the collection with a data field.

Signature

createData(properties: {*: any}): <Document>

Description

Creates a document in the collection with the provided properties fields and values.

If the following fields are included, they populate the document .data field: id, ts, ttl, and data. Otherwise, the data field isn’t instantiated.

Parameters

Parameter Type Required Description

properties

Object

Yes

Fields to populate the document, including the data field.

properties that populate the .data field

Name Type Required Description

ttl

Time

Timestamp indicating when to remove the document. When the document is removed, it ceases to exist.
Default = null Causes the document to persist indefinitely.

id

Number

User-defined document id.

data

Any

The key:value pairs to populate the data field.

Return value

Type Description

Document

New document with a data field populated with provided properties.

Examples

  1. Create a document with a data field:

    Books.createData({
      name: "Then and Now",
      author: "W. Somerset Maugham",
      id: "0099286866",
      data: {
        published: "1946",
        country: "United Kingdom"
      }
    })
    {
      id: "386653354970841153",
      coll: Foo,
      ts: Time("2024-01-11T19:10:24.020Z"),
      name: "Then and Now",
      author: "W. Somerset Maugham",
      data: {
        data: {
          published: "1946",
          country: "United Kingdom"
        },
        id: "0099286866"
      }
    }
  2. Access the data field:

    Books.byId("386653354970841153")!.data.id
    "0099286866"

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!