Collection document definition

Learn: Collection schema

We recommend you use FSL to create and update user-defined collections. See Collection schema.

A collection document definition is an FQL version of an FSL collection schema.

{
  name: "Product",
  coll: Collection,
  ts: Time("2099-06-18T19:49:25.725Z"),
  history_days: 3,
  ttl_days: 5,
  computed_fields: {
    InventoryValue: {
      body: "(.quantity * .price)",
      signature: "Number"
    }
  },
  constraints: [
    {
      unique: [
        {
          field: ".name",
          mva: false
        },
        {
          field: ".description",
          mva: false
        },
        {
          field: ".categories",
          mva: true
        }
      ],
      status: "active"
    },
    {
      check: {
        name: "posQuantity",
        body: "(doc) => doc.quantity >= 0"
      }
    }
  ],
  document_ttls: true,
  migrations: [
    {
      add: {
        field: ".typeConflicts"
      }
    },
    {
      add: {
        field: ".quantity"
      }
    },
    {
      backfill: {
        field: ".quantity",
        value: "0"
      }
    },
    {
      drop: {
        field: ".internalDesc"
      }
    },
    {
      move_conflicts: {
        into: ".typeConflicts"
      }
    },
    {
      move: {
        field: ".desc",
        to: ".description"
      }
    },
    {
      split: {
        field: ".creationTime",
        to: [
          ".creationTime",
          ".creationTimeEpoch"
        ]
      }
    }
  ],
  indexes: {
    byName: {
      terms: [
        {
          field: ".name",
          mva: false
        }
      ],
      values: [
        {
          field: ".quantity",
          order: "desc",
          mva: false
        },
        {
          field: ".categories",
          order: "desc",
          mva: true
        }
      ],
      queryable: true,
      status: "complete"
    }
  },
  wildcard: "Any",
  fields: {
    name: {
      signature: "String?"
    },
    description: {
      signature: "String?"
    },
    price: {
      signature: "Double",
      default: "0.00"
    },
    quantity: {
      signature: "Int",
      default: "0"
    },
    store: {
      signature: "Ref<Store>?"
    },
    backorderLimit: {
      signature: "Int?"
    },
    backordered: {
      signature: "Boolean?"
    },
    categories: {
      signature: "Array<String>?"
    },
    creationTime: {
      signature: "Time",
      default: "Time.now()"
    },
    creationTimeEpoch: {
      signature: "Int?"
    },
    typeConflicts: {
      signature: "{ *: Any }?"
    }
  }
}

Fields

Field Type Description

name

Name of the collection.

coll

The Collection collection name.

ts

Timestamp of the most recent document write.

history_days

Number of days of history to retain for collection documents. When the number of days lapses, document snapshots older than the interval are removed. Does not affect the current version of documents.

Defaults to 0 (Retain only current documents). See Temporality.

ttl_days

Documents are deleted ttl_days number of days after their last write.

Defaults to null (Retained documents indefinitely).

computed_fields

FQL version of the collection schema’s computed fields. See Computed field definitions

constraints

FQL version of the collection schema’s check and unique constraints. See Check constraints and Unique constraints.

document_ttls

Boolean | null

If true, you can write to the ttl field in the collection’s documents.

document_ttls does not stop ttl-related deletions or affect ttl values set by the collection schema’s ttl_days field.

migrations

FQL version of the collection schema’s migrations block. See Migrations block.

indexes

FQL version of the collection schema’s index definitions. See Index definitions.

wildcard

FQL version of the collection schema’s wildcard constraint. See Wildcard constraints.

fields

FQL version of the collection schema’s field definitions. See Field definitions.

data

Arbitrary user-defined metadata.

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!