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:

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

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!