FQL v4 will be decommissioned on June 30, 2025. Ensure that you complete your migration from FQL v4 to FQL v10 by that date.

Fauna accounts created after August 21, 2024 must use FQL v10. These accounts will not be able to run FQL v4 queries or access the v4 Dashboard.

For more details, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

Documents

This reference topic applies to FQL v4. Go to this page for the latest FQL v10 reference topics.

Documents( collection )
documents( collection )
Documents( collection )
Documents( collection )
Documents( collection )
Documents( collection )

Description

The Documents function returns the set of documents that exist in the specified collection.

Before the Documents function was introduced, you needed to create an index just to facilitate retrieving documents from a collection. See the Indexing tutorials for details.

Parameters

Parameter Type Definition and Requirements

collection

Reference

A Reference to the collection from which documents should be collected.

Returns

A Set Reference which represents all of the documents in the specified collection.

Examples

The following query returns three documents in the Letters collection (established as part of the Index tutorials):

client.query(
  q.Paginate(q.Documents(q.Collection('Letters')), { size: 3 })
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{ after: [ Ref(Collection("Letters"), "104") ],
  data:
   [ Ref(Collection("Letters"), "101"),
     Ref(Collection("Letters"), "102"),
     Ref(Collection("Letters"), "103") ] }
result = client.query(
  q.paginate(q.documents(q.collection('Letters')), size=3)
)
print(result)
{'after': [Ref(id=104, collection=Ref(id=Letters, collection=Ref(id=collections)))], 'data': [Ref(id=101, collection=Ref(id=Letters, collection=Ref(id=collections))), Ref(id=102, collection=Ref(id=Letters, collection=Ref(id=collections))), Ref(id=103, collection=Ref(id=Letters, collection=Ref(id=collections)))]}
result, err := client.Query(
	f.Paginate(f.Documents(f.Collection("Letters")), f.Size(3)))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[after:[{104 0xc00008f4a0 0xc00008f4a0 <nil>}] data:[{101 0xc00008f650 0xc00008f650 <nil>} {102 0xc00008f800 0xc00008f800 <nil>} {103 0xc00008f9b0 0xc00008f9b0 <nil>}]]
try
{
    Value result = await client.Query(
        Paginate(Documents(Collection("Letters")), size: 3)
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(after: Arr(RefV(id = "104", collection = RefV(id = "Letters", collection = RefV(id = "collections")))),data: Arr(RefV(id = "101", collection = RefV(id = "Letters", collection = RefV(id = "collections"))), RefV(id = "102", collection = RefV(id = "Letters", collection = RefV(id = "collections"))), RefV(id = "103", collection = RefV(id = "Letters", collection = RefV(id = "collections")))))
System.out.println(
    client.query(
        Paginate(Documents(Collection("Letters"))).size(3)
    ).get());
{after: [ref(id = "104", collection = ref(id = "Letters", collection = ref(id = "collections")))], data: [ref(id = "101", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "102", collection = ref(id = "Letters", collection = ref(id = "collections"))), ref(id = "103", collection = ref(id = "Letters", collection = ref(id = "collections")))]}
Paginate(Documents(Collection('Letters')), { size: 3 })
{
  after: [ Ref(Collection("Letters"), "104") ],
  data: [
    Ref(Collection("Letters"), "101"),
    Ref(Collection("Letters"), "102"),
    Ref(Collection("Letters"), "103")
  ]
}
Query metrics:
  •    bytesIn:    60

  •   bytesOut:   449

  • computeOps:     1

  •    readOps:     8

  •   writeOps:     0

  •  readBytes: 1,216

  • writeBytes:     0

  •  queryTime:  12ms

  •    retries:     0

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!