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.id == "401670797851099213")
{
  id: "401670938431586381",
  coll: Token,
  ts: Time("2099-06-25T13:28:27.660Z"),
  document: Customer("401670797851099213")
}

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!