Document

Learn: Documents

You add data to Fauna as JSON-like documents, stored in collections.

Document fields

All documents contain the id, coll, ts, and optional ttl metadata fields. Documents in user-defined collections also typically contain user-defined fields. For example:

{
  id: "392886847463751746",
  coll: Product,
  ts: Time("2099-04-10T16:50:12.850Z"),
  ttl: Time("2099-04-15T16:50:12.850Z"),
  name: "key limes",
  description: "Conventional, 16 oz bag",
  price: 299,
  stock: 100,
  category: Category("401610017107607625")
}
Field Type Immutable Description

id

ID

Yes

Main document identifier. It must be unique in the collection. The identifier gets serialized to a string-encoded 64-bit Int.

The id is assigned by Fauna but can be set when the document is created using the document collection.create() method.

The id field can be can be covered by an index value.

The id and coll fields together represent a reference, which is a unique document identifier.

coll

Yes

Collection of which the document is a member. The coll field can’t be indexed.

ts

Yes

Document last changed timestamp. Updated only on document write. The timestamp is propagated to all child documents.

ttl

Time or null

Document time-to-live (TTL), if set.

<USER_DERFINED_FIELD>

User-defined document field.

Schema method names and schema metadata field names are reserved and can’t be used as a field name but can be used in nested objects.

You can enforce typing and constraints for user-defined fields in a collection using collection schema.

Instance methods

You can use the following instance methods to manage a document in FQL.

Method Description

Delete a document.

Test if a document exists.

Replace all document fields.

Replace document data field contents.

Update document fields.

Update document data field contents.

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!