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

Number | String

Document identifier. If id is not provided, the document id is assigned by Fauna.

The id must be a 64-bit unsigned integer. Setting id to a negative value causes a QueryRuntimeError error with a constraint_failure of id must be nonnegative.

The id can be a Number type or a String type provided it can be coerced to an integer that is in the range 253-1. A QueryRuntimeError is generated with a constraint_failure of Invalid type provided if:

  • id is a string that doesn’t represent an integer in the range 253-1

  • id is a Number, passed as a String, that is greater than 253-1

  • id is a datatype other than Number or String

The id is returned as a String even if a Number type value is provided.

The id is immutable after it is assigned.

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

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!