collectionDef.replace()

We recommend you use FSL to create and update user-defined functions (UDFs). See FSL function schema.

Replaces a collection definition.

Signature

replace(data: { *:Any }) => CollectionDef

Description

The update() method replaces a collection definition, represented as a Collection document.

Collection documents have the CollectionDef type and are an FQL version of the FSL collection schema.

Staged schema

If a database has staged schema, this method interacts with the database’s staged schema, not the active 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.

Parameters

Parameter Type Required Description

data

Object containing valid Collection document fields.

Yes

The replacement collection definition, represented as a Collection document. Fields not present, except immutable metadata fields, are removed.

Return value

Type Description

CollectionDef

Definition for the updated collection, represented as a Collection document.

Examples

Collection.byName("Customer")!.replace({
  name: "Customer",
  history_days: 0,
  migrations: [
    {
      add_wildcard: {}
    }
  ],
  computed_fields: {
    cart: {
      body: "(customer) => Order.byCustomerAndStatus(customer, \"cart\").first()",
      signature: "Order?"
    },
    orders: {
      body: "(customer) => Order.byCustomer(customer)",
      signature: "Set<Order>"
    }
  },
  wildcard: "Any",
  constraints: [
    {
      unique: [
        {
          field: ".email",
          mva: false
        }
      ],
      status: "active"
    }
  ],
  indexes: {
    byEmail: {
      terms: [
        {
          field: ".email",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    }
  },
  document_ttls: true,
  ttl_days: 10,
  fields: {
    name: {
      signature: "String"
    },
    email: {
      signature: "String"
    },
    address: {
      signature: "{ street: String, city: String, state: String, postalCode: String, country: String }"
    }
  }
})
{
  name: "Customer",
  coll: Collection,
  ts: Time("2099-10-03T21:50:53.550Z"),
  migrations: [
    {
      add_wildcard: {}
    }
  ],
  indexes: {
    byEmail: {
      terms: [
        {
          field: ".email",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    }
  },
  constraints: [
    {
      unique: [
        {
          field: ".email",
          mva: false
        }
      ],
      status: "active"
    }
  ],
  wildcard: "Any",
  ttl_days: 10,
  computed_fields: {
    cart: {
      body: "(customer) => Order.byCustomerAndStatus(customer, \"cart\").first()",
      signature: "Order?"
    },
    orders: {
      body: "(customer) => Order.byCustomer(customer)",
      signature: "Set<Order>"
    }
  },
  fields: {
    name: {
      signature: "String"
    },
    email: {
      signature: "String"
    },
    address: {
      signature: "{ street: String, city: String, state: String, postalCode: String, country: String }"
    }
  },
  history_days: 0,
  document_ttls: true
}

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!