Collection.where()

Get the set of accessible collections in the database.

Signature

Collection.where(predicate: () => Boolean)): Set<CollectionDef>

Collection.where(predicate: (val: Collection) => Boolean)): Set<CollectionDef>

Description

Each collection in a Fauna database is represented by a collection object. The Collection.where() method gets the set of accessible collection objects that match the predicate function.

If Collection.where() is the last value in a query, the first page of the set is returned.

Parameters

Parameter Type Required Description

predicate

Function

Yes

Anonymous function that compares values in each collection document and returns true for matches or false for mismatches.

predicate parameters:

Parameter Type Required Description

val

Collection

Collection object to compare. If omitted, use dot notation to access collection properties.

Return value

Type Description

Set<CollectionDef>

Set representing the collections that match the predicate function. The method returns the empty set if there are no matching collections.

Examples

Collection.where(.name.includes('te'))
{
  data: [
    {
      name: "testit1",
      coll: Collection,
      ts: Time("2022-12-28T17:32:01.440Z")
    },
    {
      name: "doesnotexist",
      coll: Collection,
      ts: Time("2023-02-18T19:22:26.355Z"),
      indexes: {},
      constraints: []
    }
  ]
}

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!