collection.definition
| Learn: Collections |
|---|
|
To look up a definition using an alias, use
|
Get a collection definition, represented
as a Collection
document with the CollectionDef type.
Description
A collection’s schema, represented as a
Collection
document with the CollectionDef type.
Collection documents are FQL versions of a database’s FSL
collection schema. Collection documents
have the CollectionDef type. See
Collections.
You access the .definition property using an existing collection’s name.
Definition properties
You can use dot or bracket notation to access specific fields in the definition. See Access definition properties.
Definition methods
The definition property supports
collection instance methods.
Return value
| Type | Description |
|---|---|
Definition for the collection, represented as a
|
Examples
Basic example
// Get the definition for
// the `Customer` collection.
Customer.definition
{
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: 10,
constraints: [
{
unique: [
{
field: ".email",
mva: false
}
],
status: "active"
}
],
document_ttls: true,
migrations: [
{
add_wildcard: {}
}
]
}
Access definition properties
Use dot or bracket notation to access specific fields in the definition:
// Access `computed_fields` definitions for
// the `Customer` collection.
Customer.definition.computed_fields
// Only returns computed field definitions.
{
cart: {
body: "(customer) => Order.byCustomerAndStatus(customer, \"cart\").first()",
signature: "Order?"
},
orders: {
body: "(customer) => Order.byCustomer(customer)",
signature: "Set<Order>"
}
}