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: "412655134325080576",
      coll: Key,
      ts: Time("2099-07-19T20:53:15.250Z"),
      role: "admin",
      data: {
        desc: "Admin key for prod app database"
      }
    },
    {
      id: "412655134325080577",
      coll: Key,
      ts: Time("2099-07-28T02:25:35.050Z"),
      role: "server",
      data: {
        desc: "Server 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!