collection.firstWhere()
Get the first matching accessible document in the collection.
Signature
firstWhere(predicate: () => Boolean)) => <Collection> | Null
firstWhere(predicate: (val: Document) => Boolean)) => <Collection> | Null
Description
Gets the first accessible document in the collection that matches the predicate function.
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
predicate |
Anonymous function that compares values in each document in the
collection and returns |
Return value
One of:
Type | Description |
---|---|
Document |
First accessible document matching the predicate function. |
When no document matches the predicate function or all matching documents are inaccessible. |
Examples
Product.firstWhere(.stock < 20)
{
id: "999",
coll: Product,
ts: Time("2099-07-30T21:56:38.130Z"),
name: "taco pinata",
description: "Giant Taco Pinata",
price: 2399,
stock: 10,
category: Category("123")
}
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!