The Fauna service will be ending on May 30, 2025.

For more information on the service wind down, see our announcement and the Fauna Service End-of-Life FAQ.

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"))))
System.out.println(
    client.query(
        Paginate(Tokens())
    ).get());
{data: [ref(id = "1", collection = ref(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.

\