Database.where()

Get the set of matching databases.

Signature

Database.where(predicate: () => Boolean)): Set<Database>

Database.where(predicate: (val: DatabaseDef) => Boolean)): Set<Database>

Description

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

If Database.where() is the last expression 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 child database document and returns true for matches or false if there is no match.

predicate parameters:

Parameter Type Required Description

val

DatabaseDef

Database singleton to compare. If omitted, use dot notation to access database properties.

Return value

Type Description

Set<Database>

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

Examples

Database.where(.name.includes("Best"))
{
  data: [
    {
      name: "BestOfClass",
      coll: Database,
      ts: Time("2023-06-05T19:46:51.110Z"),
      global_id: "ywmp5wua1yyre",
      typechecked: true,
      priority: 100
    }
  ]
}

Database.where(childDB => childDB.priority == 10)
{
  data: [
    {
      name: "Growers",
      coll: Database,
      ts: Time("2023-06-05T19:44:23.040Z"),
      global_id: "ywmp5m111yyre",
      typechecked: true,
      priority: 10
    }
  ]
}

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!