create()

Create a document in the collection.

Signature

create(data: { id: ID | Null, ttl: Time | Null, *: Any }): <Document>

Description

Creates a document in the collection with the provided data.

Parameters

Parameter Type Required Description

data

Object

Yes

Object describing the document properties and values.

data fields

Name Type Required Description

id

ID | Null

Unique, immutable identifier for the document in the collection. If null or not provided, Fauna assigns an id.

To provide an id:

  • Create an ID using ID().

  • Provide a literal Int or literal String that be coerced into a 64-bit unsigned integer in the 253-1 range.

id is returned as a String.

ttl

Time | Null

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

New document.

Examples

Product.create({ name: "key limes" })
{
  id: "357102606290518049",
  coll: Product,
  ts: Time("2099-02-19T14:53:53.940Z"),
  name: "key limes"
}

See also

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!