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.

collection.all()

Learn: Documents

Get a Set of all documents in a collection.

Signature

all() => Set<A>

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

Description

Gets a Set containing all documents in a collection. To limit the returned Set, you can provide an optional range.

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

Built-in index

Fauna implements .all() as a built-in collection index. The index uses ascending the document id as its only index value. The .all() index has no index terms.

Like all indexes, the .all() index reads historical data when queried.

Parameters

Parameter Type Required Description

range

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

Specifies a range of collection documents in the form { from: start, to: end }. from and to arguments should be in the order returned by an unbounded 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 collection documents are returned.

Range parameters

Name Type Required Description

from

Any

Beginning of the range (inclusive). Must be a document in the collection.

to

Any

End of the range (inclusive). Must be a document in the collection.

Return value

Type Description

Set<Document>

All matching documents in the collection.

Examples

Range examples

  1. First, get all documents in the collection instance:

    Category.all()
    {
      data: [
        {
          id: "123",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "party",
          description: "Party Supplies"
        },
        {
          id: "456",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "frozen",
          description: "Frozen Foods"
        },
        {
          id: "789",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "produce",
          description: "Fresh Produce"
        }
      ]
    }
  2. Provide a range to get all documents beginning with a given document:

    let frozen = Category.byName("frozen").first()
    Category.all({from: frozen})
    {
      data: [
        {
          id: "456",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "frozen",
          description: "Frozen Foods"
        },
        {
          id: "789",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "produce",
          description: "Fresh Produce"
        }
      ]
    }
  3. Get all documents beginning up to a given document:

    let frozen = Category.byName("frozen").first()
    Category.all({to: frozen})
    {
      data: [
        {
          id: "123",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "party",
          description: "Party Supplies"
        },
        {
          id: "456",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "frozen",
          description: "Frozen Foods"
        }
      ]
    }
  4. Get all documents between the given from and to range parameters (inclusive):

    let party = Category.byName("party").first()
    let frozen = Category.byName("frozen").first()
    Category.all({from: party, to: frozen})
    {
      data: [
        {
          id: "123",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "party",
          description: "Party Supplies"
        },
        {
          id: "456",
          coll: Category,
          ts: Time("2099-07-30T21:56:38.130Z"),
          products: "hdW...",
          name: "frozen",
          description: "Frozen Foods"
        }
      ]
    }

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!