Collection.firstWhere()

Get the first matching accessible collection.

Signature

Collection.firstWhere(predicate: () => Boolean)): CollectionDef | NullCollectionDef

Collection.firstWhere(predicate: (val: Collection) => Boolean)): CollectionDef | NullCollectionDef

Description

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

Parameters

Parameter Type Required Description

predicate

Function

Yes

Anonymous function that compares values in each collection document and returns true for matches or false for mismatches.

predicate parameters:

Parameter Type Required Description

val

Collection

Collection object to compare. If omitted, use dot notation to access collection properties.

Return value

One of:

Type Description

CollectionDef

First accessible collection definition document matching the predicate function.

NullCollectionDef

No collections match the predicate function or all matching collections are inaccessible.

Examples

Collection.firstWhere(.name.includes('te'))
{
  name: "Letter",
  coll: Collection,
  ts: Time("2022-10-25T21:01:19.310Z")
}

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!