collectionDef.update()
We recommend you use FSL to create and update user-defined functions (UDFs). See FSL function schema. |
Updates a collection definition.
Description
Updates a
Collection
document
with fields from a provided data object.
During the update, fields from the data object are copied to the document, creating new fields or updating existing fields. The operation is similar to a merge.
Collection
documents are FQL versions of a database’s FSL
collection schema. Collection
documents
have the CollectionDef type. See
Collections.
Staged schema
If a database has staged schema, this method interacts with the database’s staged schema, not the active schema.
You can’t rename a collection while a database has staged schema.
If the database has no staged schema, using this method is equivalent to making an unstaged schema change. Changes are applied immediately to the database’s active schema.
Unstaged schema changes that trigger an index build may result in downtime where the index is not queryable.
Avoid concurrent schema changes
Concurrent unstaged schema changes can cause contended transactions, even if the changes affect different resources. This includes unstaged changes made using:
-
The Fauna CLI
-
The Fauna Dashboard
-
The Fauna Core HTTP API’s Schema endpoints
A schema change triggers a transaction that validates the entire database schema. To avoid errors, do one of the following instead:
-
Perform unstaged schema changes sequentially
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
data |
Document fields for the
For supported document fields, see the
The object can’t include the following metadata fields:
|
Return value
Type | Description |
---|---|
The updated
|
Examples
Collection.byName("Customer")!.update({
ttl_days: 15
})
{
name: "Customer",
coll: Collection,
ts: Time("2099-10-03T20:45:53.780Z"),
history_days: 0,
fields: {
name: {
signature: "String"
},
email: {
signature: "String"
},
address: {
signature: "{ street: String, city: String, state: String, postalCode: String, country: String }"
}
},
wildcard: "Any",
computed_fields: {
cart: {
body: "(customer) => Order.byCustomerAndStatus(customer, \"cart\").first()",
signature: "Order?"
},
orders: {
body: "(customer) => Order.byCustomer(customer)",
signature: "Set<Order>"
}
},
indexes: {
byEmail: {
terms: [
{
field: ".email",
mva: false
}
],
values: [
{
field: ".email",
order: "desc",
mva: false
},
{
field: ".name",
order: "asc",
mva: false
}
],
queryable: true,
status: "complete"
},
},
ttl_days: 15,
constraints: [
{
unique: [
{
field: ".email",
mva: false
}
],
status: "active"
}
],
document_ttls: true,
migrations: [
{
add_wildcard: {}
}
]
}
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!