Document fields

This describes the structure of a Fauna document.

Fields

Field Type Immutable Description

coll

Yes

Collection of which the document is a member.

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 create() method.

The id field can be covered by an index.

ts

Yes

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

ttl

Time or null

No

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

data

No

User-defined document fields. The data field can’t be created.

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

Field values can be any supported data type.

Reference usage

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

  • The coll field can’t be indexed.

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

  • When a document is nested in another document, only the id and coll fields of the nested document are stored, as shown in this example:

    MagicalCreature.firstWhere(.name == "Hen Wen")!.update({
      owner: Character.firstWhere(.name == "Taran"),
    })
    {
      id: "345963092586267136",
      coll: MagicalCreature,
      ts: Time("2022-10-24T06:59:16.180Z"),
      name: "Hen Wen",
      owner: {
        id: "345963092567392768",
        coll: Character
      }
    }

    When a nested document field is selected, using projection or dot notation, the full document is available, as shown in these examples:

    MagicalCreature.firstWhere(.name == "Hen Wen") { owner }
    {
      owner: {
        id: "345963092567392768",
        coll: Character,
        ts: Time("2022-10-19T15:56:05.910Z"),
        name: "Taran",
        screen_name: "taran86"
      }
    }

    MagicalCreature.firstWhere(.name == "Hen Wen") { owner.name }
    {
      ownerName: "Taran"
    }

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!