Key Concepts

Documents

Documents are the basic unit of information in Fauna. All user data is stored in documents, and everything in the Fauna data model — including databases, collections, indexes, and user-defined functions — is defined in a document.

Documents are similar to JSON objects, with keys and values. A typical document looks like this:

{
  ref: Ref(Collection("myCollection"), "302044124774662656"),
  ts: 1624310574250000,
  data: {
           'stringValue': 'abc123',
           'arrayValue': ['abc', 1, 2, 3]
           'integerValue': 358192,
           'objectValue': { 'a': 1, 'b': 2, 'c': 3 }
        }
}

Documents may be nested. The value for any key may itself be a document.

See the Limits page for details on document size and transaction limits.

Every document belongs to a specific collection, similar to a table in other database systems, which groups similar documents together. Documents within collections are not required to share the same structure.

More information

To learn more about Fauna documents, see Documents.

Collections

Collections are containers for holding documents. They serve the same purpose in Fauna’s data model that tables do in SQL databases. A database may contain one or more collections, and a collection may have any number of documents. To create a collection, use the CreateCollection function.

Once the collection has been created, it is possible to create documents within the collection using the Fauna Query Language or the GraphQL API.

When a collection is deleted, associated documents become inaccessible and are deleted asynchronously.

More information

To learn more about Fauna collections, see Collections.

References

A Reference is the unique identifier for a document in a particular database.

Each Reference is a compound value, composed of:

  • a reference to the collection containing the document: either a user-defined collection, or a system schema collection, such as Tokens.

  • a document ID: a string-encoded 64-bit integer. Note that References to system schema collections do not have document IDs; the name of the system schema collection is its unique identifier.

Together, the collection reference and the document ID refer to a distinct document: no two documents in a database can share the same reference.

More information

To learn more about References, see the Reference data type.

Indexes

Indexes allow for the organization and retrieval of documents by attributes other than their Reference. They act as a lookup table that improves the performance of finding documents: instead of reading every single document to find the one(s) that you are interested in, you query an index to find those documents.

More information

To learn more about indexes, see the complete Index reference page.

User-defined functions

The Fauna Query Language provides many built-in functions that can be used to query and modify a database. User-defined functions (or UDFs) provide a mechanism to store and run commonly used Fauna queries.

User-defined functions are used to combine functions, built-in or user-defined, into queries that can be stored and executed repeatedly.

More information

To learn more about user-defined functions, see the complete reference page.

Region groups

Region Groups provide control over where your data resides: each database, its storage, and its compute services exist in a specific geographic region. The capability makes it possible to comply with data locality legislation, such as the General Data Protection Regulation (GDPR) in Europe, while benefiting from Fauna’s distributed service features.

More information

To learn more, see Region Groups.

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!