Database.firstWhere()
Gets the first Database
collection document that matches a provided predicate.
Signature
Database.firstWhere(predicate: () => Boolean)) => <Document> | NullDatabaseDef
Database.firstWhere(predicate: (val: DatabaseDef) => Boolean)) => <Document> | NullDatabaseDef
Description
The Database.firstWhere()
method gets the first Database
collection document
that match a provided predicate.
If the predicate is true
for a Database
document, the document is included
in the Set. Otherwise, the document is excluded.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
predicate |
Yes |
Anonymous function that compares values in each database document
and returns |
Return value
One of:
Type | Description |
---|---|
First accessible database document matching the predicate function. |
|
|
No database matches the predicate function or all matching databases are inaccessible. |
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
}
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!