Database.firstWhere()

Get the first matching database.

Signature

Database.firstWhere(predicate: () => Boolean)): <Document> | NullDatabaseDef

Database.firstWhere(predicate: (val: DatabaseDef) => Boolean)): <Document> | NullDatabaseDef

Description

Each collection in a Fauna database is represented by a Database object. This method returns the first accessible Database object that matches the predicate function.

Parameters

Parameter Type Required Description

predicate

Function

Yes

Anonymous function that compares values in each 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

One of:

Type Description

DatabaseDef

First accessible database document matching the predicate function.

NullDatabaseDef

No database matches the predicate function or all matching databases are inaccessible.

Examples

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

Database.firstWhere(childDB => childDB.priority > 10)
{
  name: "BestOfClass",
  coll: Database,
  ts: Time("2023-06-05T19:46:51.110Z"),
  global_id: "ywmp5wua1yyre",
  typechecked: true,
  priority: 100
}

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!