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 tokens

Problem

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

Solution

Use the Tokens function combined with the Paginate function:

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

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

  •   bytesOut:   81

  • computeOps:    1

  •    readOps:    8

  •   writeOps:    0

  •  readBytes:  418

  • writeBytes:    0

  •  queryTime: 11ms

  •    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!