Collection()

Dynamically get the Collection by name.

Signature

Collection(name: String): Any

Description

The Collection() method gets the name collection.

Parameters

Parameter Type Required Description

name

String

Yes

Collection name

Return value

Type Description

Any

The name collection.

Examples

Get the collection by directly naming the collection:

Product.where(.name == 'pizza')
{
  data: [
    {
      id: "386968888565301316",
      coll: Product,
      ts: Time("2024-01-15T06:45:40.390Z"),
      name: "pizza",
      description: "Frozen Cheese",
      price: 4.99,
      quantity: 92,
      store: Store.byId("386968888560058436"),
      backorderLimit: 15,
      backordered: false
    }
  ]
}

 

This equivalent expression gets the collection by passing the name of the collection as a parameter:

Collection('Product').where(.name == 'pizza')
{
  data: [
    {
      id: "386968888565301316",
      coll: Product,
      ts: Time("2024-01-15T06:45:40.390Z"),
      name: "pizza",
      description: "Frozen Cheese",
      price: 4.99,
      quantity: 92,
      store: Store.byId("386968888560058436"),
      backorderLimit: 15,
      backordered: false
    }
  ]
}

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!