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:

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"))))
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>}]]
System.out.println(
    client.query(
        Paginate(Tokens())
    ).get());
{data: [ref(id = "1", collection = ref(id = "tokens"))]}
client.query(
  q.Paginate(q.Tokens())
)
.then((ret) => console.log(ret))
.catch((err) => console.error('Error: %s', err))
{ data: [ Ref(Tokens(), "1") ] }
result = client.query(
  q.paginate(q.tokens())
)
print(result)
{'data': [Ref(id=1, collection=Ref(id=tokens))]}
try {
  println(Await.result(
    client.query(
      Paginate(Tokens())
    ),
    5.seconds
  ))
} catch {
  case unknown: Throwable => println("Error: " + unknown.getMessage())
}
{data: [ref(id = "1", collection = ref(id = "tokens"))]}
Paginate(Tokens())
{ data: [ Ref(Tokens(), "1") ] }

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.

More information

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!