Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Collection.byName()

Learn: Collections

Get a collection definitions by its name.

Signature

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

Description

Gets a collection definitions, represented as a Collection document, by its 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

true

name of a Collection document.

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!