collection.definition

collection.definition is a deprecated. Use Collection.byName() instead.

To look up a definition using an alias, use FQL.Schema.defForIdentifier().

Get or update a collection’s definition, represented as a Collection document with the CollectionDef type.

Signature

<Collection>.definition: CollectionDef

Description

The definition property is a collection’s schema, represented as a Collection document with the CollectionDef type. The document is an FQL version of the FSL collection schema.

You access the 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

CollectionDef

Definition for the collection, represented as a Collection document.

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>"
  }
}

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!