Database.firstWhere()

Learn: Databases and multi-tenancy

Get the first child database document that matches a provided predicate.

Signature

Database.firstWhere(pred: (DatabaseDef => Boolean)) => DatabaseDef | Null

Description

Gets the first child database, represented as an Database document, that matches a provided predicate function.

Fauna stores child databases as documents in the parent database’s Database system collection. Database documents have the DatabaseDef type.

Scope

The Database collection only contains documents for the direct child databases of the database scoped to your authentication secret. You can’t use the Database collection to access parent, peer, or other descendant databases.

Using FQL to create or manage top-level databases is not supported.

Parameters

Parameter Type Required Description

pred

Predicate function

Yes

Anonymous predicate function that:

The method returns the first Database document for which the predicate returns true.

Return value

One of:

Type Description

DatabaseDef

First Database document that matches the predicate.

Null

No Database document matches the predicate.

Examples

Database.firstWhere(.name.includes("child"))
{
  name: "childDB",
  coll: Database,
  ts: Time("2099-06-24T21:54:38.890Z"),
  typechecked: true,
  global_id: "ysjpykbahyyr1",
  priority: 10
}
Database.firstWhere(childDB => childDB.priority > 5)
{
  name: "childDB",
  coll: Database,
  ts: Time("2099-06-24T21:54:38.890Z"),
  global_id: "ysjpykbahyyr1",
  priority: 10,
  typechecked: true
}
\