Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Key.firstWhere()

Learn: Keys

Get the first key that matches a provided predicate.

Signature

Key.firstWhere(pred: (Key => Boolean)) => Key | Null

Description

Gets the first key, represented as a Key document, that matches a provided predicate function.

A key is a type of authentication secret used for anonymous access to a Fauna database. Unlike tokens, keys are not associated with an identity.

Parameters

Parameter Type Required Description

pred

Predicate function

Yes

Anonymous predicate function that:

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

Return value

One of:

Type Description

Key

First Key document that matches the predicate.

Null

No Key document matches the predicate.

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!