Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

Key.all()

Learn: Keys

Get a Set of all keys.

Signature

Key.all() => Set<Key>

Key.all(range: { from: Any } | { to: Any } | { from: Any, to: Any }) => Set<Key>

Description

Gets a Set containing all keys, represented as Key documents, for the database. To limit the returned Set, you can provide an optional range.

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

Parameters

Parameter Type Required Description

range

{ from: Any } | { to: Any } | { from: Any, to: Any }

Specifies a range of Key documents in the form { from: start, to: end }. from and to arguments should be in the order returned by an unbounded Key.all() call. See Range examples.

The Set only includes documents in this range (inclusive). Omit from or to to run unbounded range searches.

If a range is omitted, all Key documents are returned.

Range parameters

Name Type Required Description

from

Any

Beginning of the range (inclusive). Must be an Key document.

to

Any

End of the range (inclusive). Must be an Key document.

Return value

Type Description

Set<Key>

Set of Key documents in the provided range. If a range is omitted, all Key documents are returned.

The Set is empty if:

  • The database has no keys.

  • There are no keys in the provided range.

  • The provided range’s from value is greater than to.

Examples

Range examples

  1. Get all keys for the database:

    Key.all()
    {
      data: [
        {
          id: "111",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          role: "admin",
          data: {
            desc: "Admin key for prod app database"
          }
        },
        {
          id: "222",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          role: "server",
          data: {
            desc: "Server key for prod app database"
          }
        },
        {
          id: "333",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          role: "server-readonly",
          data: {
            desc: "Server-readonly key for prod app database"
          }
        }
      ]
    }
  2. Get a Set of Key documents from ID 111 (inclusive) to ID 222 (inclusive):

    Key.all({ from: Key.byId("111"),
              to: Key.byId("222") })
    {
      data: [
        {
          id: "111",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          role: "admin",
          data: {
            desc: "Admin key for prod app database"
          }
        },
        {
          id: "222",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          role: "server",
          data: {
            desc: "Server key for prod app database"
          }
        }
      ]
    }
  3. Get a Set of keys up to ID 222 (inclusive):

    Key.all({ to: Key.byId("222") })
    {
      data: [
        {
          id: "111",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          role: "admin",
          data: {
            desc: "Admin key for prod app database"
          }
        },
        {
          id: "222",
          coll: Key,
          ts: Time("2099-07-19T20:53:15.250Z"),
          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!