Key.firstWhere()

Get the first matching accessible Key.

Signature

Key.firstWhere(predicate: () => Boolean)) => Key | NullKey

Key.firstWhere(predicate: (val: Key) => Boolean)) => Key | NullKey

Description

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

Parameters

Parameter Type Required Description

predicate

Function

An anonymous function that compares values in each Key document and returns true for matches or false for mismatches.

predicate parameters:

Parameter Type Required Description

val

Key

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

Return value

One of:

Type Description

Key

First accessible key matching the predicate function.

NullKey

When no keys match the predicate function or all matching keys are inaccessible. See NullDoc.

Examples

Key.firstWhere(.role == "admin")
{
  id: "412655134325080576",
  coll: Key,
  ts: Time("2099-07-19T20:53:15.250Z"),
  role: "admin",
  data: {
    desc: "Admin key for prod app database"
  }
}

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!