collection

Define a Collection schema, including index and unique and check constraint fields.

Syntax

[@alias(<aliasId>]
collection <collName> {
  [history_days <history days>]
  [ttl_days <time to live days>]
  [index <index name> <index config block> . . .]
  [unique <unique constraint fields> . . .]
  [check <name> <predicateBody> . . .]
  [compute <name> [: <type>] <anonymousFunction> . . .]
}

Name

collName String Required

Name of the collection. The collName must match the following regular expression but can’t be a single underscore or reserved word: [a-zA-Z_]+[a-zA-Z0-9_]*. A collName should be singular and PascalCased.

Properties

Parameter Type Required Description

history_days

Int

Number of days of document history to retain for all documents in the collection. See Temporality.

ttl_days

Int

Number of days that documents in the collection should be retained. See Temporality.

index

String

See collection.index.

unique

String

See collection.unique.

check

String

See collection.check.

compute

String

See collection.compute.

Annotations

aliasId String or Identifier

The optional @alias annotation defines a second identifier for the collection. The aliasId can be a String, "Foo", or an identifier, Foo.

Collection aliases are useful when migrating from FQL v4 and you have collection names that violate the FQL v10 naming rules. See System-level reserved Collection names.

Examples

collection Example {
  history_days 3
  ttl_days 5

  index anIndex {
    terms [.path.to.field]
    values [.field1, desc(.field2), asc(.field3), desc(mva(.field4))]
  }

  unique [.field1, mva(.arrField)]
  check isok ((doc) => doc.ok)
  compute p = ((doc) => doc.a + 1)
  compute q: Number = (.b - 1)
}

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!