Collections
reference: |
A Collection groups documents in a database. In a relational database, a collection is 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 document version history for as long as you want.
Collections exist as global values in the Fauna environment.
Each collection includes a definition document that defines the collection
name and can optionally define indexes and other metadata. Top-level objects
with the names of each collection exist so that operations on the collections
and their documents can be performed. The top-level Collection
object has
methods that can manage collections.
A database may have zero or more user-defined collections, and a collection can have any number of documents.
Fauna provides a set of internal collections that can be used to manage database resources.
See the Collection document definition reference documentation for a description of the collection definition data structure.
Document retention
A document can include an optional ttl
(time-to-live) field that contains the
document’s expiration timestamp. After the ttl
timestamp passes, Fauna
permanently deletes the document.
You can use a collection schema’s ttl_days
field to set a default ttl
for
collection documents. See
Set a default ttl.
You can use a collection schema’s document_ttls
field to control
whether you can write to the ttl
field for collection documents. See
Enable or
disable ttl writes.
See Document removal |
---|
Document history
Fauna stores snapshots of each document’s history. Fauna creates these snapshots each time the document receives a write.
You can use a collection schema’s history_days
field to set how many days of
document history Fauna retains for a collection’s documents.
See Document history |
---|
Indexes
See Indexes for a description of indexes defined on a collection.
Constraints
Constraints can be defined for controlling reading and writing to documents in a collection.
You can declare any number of unique constraints that define which document field values must be unique in a collection. A unique constraint can define one or more fields that must be unique in combination.
When one or more fields are part of a unique constraint, multiple documents can’t have the same combination of values for the constrained fields.
Constraints aren’t applied retroactively to existing documents. Instead, they’re applied when a new document is created or an existing document is updated.
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!