collection
Define a Collection schema, including index and unique and check constraint fields.
Syntax
[@alias(<aliasId>]
collection <collName> {
[<fieldName>: <field definition> . . .]
[migrations <migrations block>]
[history_days <history days>]
[document_ttls <Boolean | Null>]
[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 |
---|---|---|---|
<fieldName> |
Document field names and definitions. See Field definitions. |
||
migrations |
See Migrations block. |
||
history_days |
Number of days of document history to retain for all documents in the collection. See Temporality. |
||
document_ttls |
If If the collection schema contains
field definitions,
|
||
ttl_days |
Number of days that documents in the collection should be retained. See Temporality. If the collection schema’s |
||
index |
See |
||
unique |
See |
||
check |
See |
||
compute |
See |
Annotations
Collection aliases are useful when migrating from FQL v4 and you have collection names that violate the FQL v10 naming rules. See reserved schema names.
Examples
collection Product {
name: String?
description: String?
price: Double = 0.00
quantity: Int = 0
store: Ref<Store>?
backorderLimit: Int?
backordered: Boolean?
categories: Array<String>?
creationTime: Time = Time.now()
creationTimeEpoch: Int?
typeConflicts: { *: Any }?
*: Any
migrations {
add .typeConflicts
add .quantity
backfill .quantity = 0
drop .internalDesc
move_conflicts .typeConflicts
move .desc -> .description
split .creationTime -> .creationTime, .creationTimeEpoch
}
unique [.name, .description, mva(.categories)]
index byName {
terms [.name]
values [desc(.quantity), desc(mva(.categories))]
}
check posQuantity ((doc) => doc.quantity >= 0)
compute InventoryValue: Number = (.quantity * .price)
history_days 3
document_ttls true
ttl_days 5
}
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!