Collection.byName()

Get a collection definition by the collection’s name.

Signature

Collection.byName(name: String) => NamedRef<CollectionDef>

Description

Gets a collection definition, represented as a Collection document, by the collection’s name.

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.

Parameters

Parameter Type Required Description

name

String

Yes

Name of the collection.

Return value

Type Description

NamedRef<CollectionDef>

Resolved reference to a Collection document Can resolve to an existing document or a NullDoc.

Examples

Collection.byName("Product")
{
  name: "Product",
  coll: Collection,
  ts: Time("2099-07-30T22:55:21.520Z"),
  history_days: 0,
  constraints: [
    {
      unique: [
        {
          field: ".name",
          mva: false
        }
      ],
      status: "active"
    },
    {
      check: {
        name: "stockIsValid",
        body: "(product) => product.stock >= 0"
      }
    },
    {
      check: {
        name: "priceIsValid",
        body: "(product) => product.price > 0"
      }
    }
  ],
  indexes: {
    byCategory: {
      terms: [
        {
          field: ".category",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    },
    sortedByCategory: {
      values: [
        {
          field: ".category",
          order: "asc",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    },
    byName: {
      terms: [
        {
          field: ".name",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    },
    sortedByPriceLowToHigh: {
      values: [
        {
          field: ".price",
          order: "asc",
          mva: false
        },
        {
          field: ".name",
          order: "asc",
          mva: false
        },
        {
          field: ".description",
          order: "asc",
          mva: false
        },
        {
          field: ".stock",
          order: "asc",
          mva: false
        }
      ],
      queryable: true,
      status: "complete"
    }
  },
  fields: {
    name: {
      signature: "String"
    },
    description: {
      signature: "String"
    },
    price: {
      signature: "Int"
    },
    category: {
      signature: "Ref<Category>"
    },
    stock: {
      signature: "Int"
    }
  }
}

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!