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.

Get a key

Reading or writing key definitions requires an admin key.

Problem

You need to retrieve the document that describes a key from the current database.

Solution

Use the Get function:

adminClient.query(
  q.Get(q.Ref(q.Keys(), '1'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Ref(Keys(), "1"),
  ts: 1631658750650000,
  role: 'admin',
  hashed_secret: '$2a$05$Df1vv7hVWEJO0./ah1uMnOx6Jas0bAXr9BKzG8tvhFLfU6rotOxIG'
}
result = adminClient.query(
  q.get(q.ref(q.keys(), "1"))
)
print(result)
{'ref': Ref(id=1, collection=Ref(id=keys)), 'ts': 1631660773940000, 'role': 'admin', 'hashed_secret': '$2a$05$flBxAwoVCmMhazskpS3G1OqTc0da0Yf9FgH71r7Z4GmH1E4UbwXe6'}
result, err := adminClient.Query(
	f.Get(f.Ref(f.Keys(), "1")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[hashed_secret:$2a$05$qjmTLEkdvEvAMBILQOYvyuCCoRCfO7lt/VqVvC3Ga8vE9enuzbkXy ref:{1 0xc000200240 0xc000200240 <nil>} role:admin ts:1631660100530000]
try
{
    Value result = await adminClient.Query(
        Get(Ref(Keys(), "1"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "1", collection = RefV(id = "keys")),ts: LongV(1631659915870000),role: StringV(admin),hashed_secret: StringV($2a$05$5Z1aSUffhrS5cgUDweRGc.s5X/nBCXYX9Dczyb.uKIfvBgjsioAvG))
Get(Ref(Keys(), "1"))
{
  ref: Ref(Keys(), "1"),
  ts: 1630713320110000,
  role: 'admin',
  hashed_secret: '$2a$05$FZsfn143PoEKFTu/LsLJaOAL9cFsXRKfeRGb4r8UbGLN2.xO86.FG'
}
Query metrics:
  •    bytesIn:   38

  •   bytesOut:  192

  • computeOps:    1

  •    readOps:    1

  •   writeOps:    0

  •  readBytes:  128

  • writeBytes:    0

  •  queryTime: 37ms

  •    retries:    0

Discussion

Once a key has been created, its secret is only displayed at that time. Afterwards, it is no longer possible to retrieve the key’s secret. If you have lost the secret associated with a key, delete the key and create a new one.

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!