Data model, querying, and security

Data model

Fauna’s data model is based on documents, collections, and databases. A database has one or more collections, and a collection contains one or more documents.

Fauna is a document-oriented database. Storing data in documents instead of rows and columns gives you greater flexibility and allows you to shape your data in the way that best fits your applications, rather than writing your applications to fit your data.

Data stored in a document looks similar to a JSON document and can include strings, integers, arrays, and other data types. All documents also include a timestamp and a unique Ref which is a combination of the document’s collection name and a string representation of an integer. Documents are stored in immutable fashion; mutations create new versions, which supports temporal querying.

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

Collections contain documents. In a relational database, a collection would be called a table. Depending on your application requirements, you can organize your documents into one collection or several, and collections can be customized to retain each document’s version history for as long as you need. Region Groups provide a way to satisfy data residency requirements.

Databases can also contain:

  • indexes, for searching and reporting on documents,

  • user-defined functions, for defining business/query logic,

  • keys, tokens, credentials, and access providers, which are all part of a Fauna database’s security configuration,

  • child databases, which are useful for multitenancy applications.

Learn more:

Querying

Fauna’s query model is based on indexes and FQL (Fauna Query Language). FQL provides functions for searching and retrieving data, and indexes provide the necessary sorting structure. If you’re coming from the SQL world, Fauna indexes are similar to views on a relational database.

Fauna features ACID compliant transactions, and consistent, global replication. The architecture of Fauna which powers these capabilities is inspired by the Calvin Protocol. Data consistency and isolation are baked in, with no additional application code necessary.

FQL includes built-in functions for CRUD, math and logical operations, as well as security and database administration. For more complex functionality, you can create user-defined functions, which can then be assigned individual roles and privileges.

Learn more:

Security

Security in Fauna gives you control over all aspects of data access and manipulation. You can use either identity-based or anonymous-based access control, with privileges as fine-grained as individual documents or as large as entire databases. You can create custom roles or use built-in roles, and assign them to users, functions, and other database entities. All Fauna databases require authentication and cannot be left accidentally unprotected.

Fauna offers authentication either anonymously with API keys, with identity-based tokens, or through third-party authentication providers by using JSON Web Tokens (JWTs).

Learn more:

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!