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.

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 Key documents 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

Set

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

Null

No documents have a matching Key or are accessible. Returns an empty set.

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!