Collection document definition

Fields

Field Type Description

name

Name of the collection.

coll

Document type name: Collection.

ts

Most recent document update timestamp.

history_days

(Optional) Document history is retained for at least history_days number of days. When the number of days lapses, events older than the interval are removed but the current version of a document is retained.

Default = 0 days.

ttl_days

(Optional) Documents are deleted ttl_days number of days after their last write.

Default = null, documents are retained indefinitely.

indexes

Indexes defined on the collection. See Indexes definition.

constraints

Constraints defined on the collection. See Unique constraints definition.

data

Object with metadata fields.

Examples

Access the collection definition object:

Letter.definition
{
  name: "Letter",
  coll: Collection,
  ts: Time("2023-02-19T14:32:29.050Z"),
  indexes: {},
  constraints: []
}

 

Collection definitions can be manipulated the same as any other document.

  1. Create an index:

    Letter.definition.update({
      indexes: {
        rareLetters: {
          terms: [{ field: "Year" }],
          values: [{ field: "Condition" }]
        }
      }
    })
    {
      name: "Letter",
      coll: Collection,
      ts: Time("2023-06-21T02:52:39.120Z"),
      indexes: {
        rareLetters: {
          terms: [
            {
              field: "Year"
            }
          ],
          values: [
            {
              field: "Condition",
              order: "asc"
            }
          ],
          queryable: true,
          status: "complete"
        }
      },
      constraints: []
    }
  2. Delete a collection:

    Letter.definition.delete()
    Collection.byName("Letter") /* not found */

    This removes the collection, its indexes, and all its documents.

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!