Key.where()

Get the Set of accessible keys in the database.

Signature

Key.where(predicate: () => Boolean)): Set<Key>

Key.where(predicate: (val: Key) => Boolean)): Set<Key>

Description

Each Key in a Fauna database is represented by a Key object. Key.where() gets the Set of accessible Key objects that match the predicate function.

The predicate function must return a Boolean.

If Key.where() is the last value in a query, the first page of the Set is returned.

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. If no document matches exist or are accessible, this method returns null.

predicate parameters:

Parameter Type Required Description

val

Key

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

Return value

Type Description

Set<Key>

Set representing the Keys that match the predicate function. Returns an empty set if there are no matching Keys.

Examples

Key.where(.data != null)
{
  data: [
    {
      id: "370714759876575266",
      coll: Key,
      ts: Time("2023-07-19T20:53:15.250Z"),
      role: "admin",
      data: {
        name: "coffee-admin"
      }
    },
    {
      id: "371460335192768546",
      coll: Key,
      ts: Time("2023-07-28T02:25:35.050Z"),
      role: "humanResources",
      data: {
        foo: "bar"
      }
    }
  ]
}

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!