Token.firstWhere()

Get the first matching accessible Token.

Signature

Token.firstWhere(predicate: () => Boolean)): <Document> | NullToken

Token.firstWhere(predicate: (val: Token) => Boolean)): <Document> | NullToken

Description

Gets the first accessible token document that matches the predicate function.

Parameters

Parameter Type Required Description

predicate

Function

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

predicate parameters:

Parameter Type Required Description

val

Token

Token document to compare. If omitted, use dot notation to access Token properties.

Return value

One of:

Type Description

Token

First accessible document matching the predicate function.

NullToken

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

Examples

Token.firstWhere(.document.coll != "stores")
{
  id: "371233004820889634",
  coll: Token,
  ts: Time("2023-07-25T14:10:32.165Z"),
  document: People.byId("370723013175279650")
}

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!