Collection.firstWhere()

Get the first collection definition matching a provided predicate.

Signature

Collection.firstWhere(pred: (CollectionDef => Boolean)) => CollectionDef | Null

Description

Gets the first collection definition, represented as a Collection document, that matches a provided predicate function.

Collection documents are FQL versions of a database’s FSL collection schema. Collection documents have the CollectionDef type. See Collections.

Staged schema

If a database has staged schema, this method interacts with the database’s staged schema, not the active schema.

Parameters

Parameter Type Required Description

pred

Predicate function

Yes

Anonymous predicate function that:

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

Return value

One of:

Type Description

CollectionDef

First Collection document that matches the predicate.

Null

No Collection document matches the predicate.

Examples

Collection.firstWhere(.name.includes('Prod'))
{
  name: "Product",
  coll: Collection,
  ts: Time("2099-04-10T14:13:05.740Z"),
  ...
}

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!