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

For more details, review the migration guide. Contact support@fauna.com with any questions.

List all keys

Reading or writing key definitions requires an admin key.

Problem

You need to retrieve a list of all keys within the current database.

Solution

Use the Keys function combined with the Paginate function:

adminClient.query(
  q.Paginate(q.Keys())
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{ data: [ Ref(Keys(), "1"), Ref(Keys(), "2") ] }
result = adminClient.query(
  q.paginate(q.keys())
)
print(result)
{'data': [Ref(id=1, collection=Ref(id=keys)), Ref(id=2, collection=Ref(id=keys))]}
result, err := adminClient.Query(
	f.Paginate(f.Keys()))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:[{1 0xc0000924b0 0xc0000924b0 <nil>} {2 0xc0000925a0 0xc0000925a0 <nil>}]]
try
{
    Value result = await adminClient.Query(
        Paginate(Keys())
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(data: Arr(RefV(id = "1", collection = RefV(id = "keys")), RefV(id = "2", collection = RefV(id = "keys"))))
Paginate(Keys())
{ data: [ Ref(Keys(), "1"), Ref(Keys(), "2") ] }
Query metrics:
  •    bytesIn:   26

  •   bytesOut:  135

  • computeOps:    1

  •    readOps:   16

  •   writeOps:    0

  •  readBytes:  842

  • writeBytes:    0

  •  queryTime: 60ms

  •    retries:    0

Discussion

The Paginate function defaults to returning up to 64 keys per page. If your database contains more than 64 keys, you can use the size parameter to retrieve up to 100,000 keys at once.

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!