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, see the v4 EOL announcement and migration guide. Contact support@fauna.com with any questions.

Delete a key

Reading or writing key definitions requires an admin key.

Problem

You need to delete a key from the current database.

Solution

Use the function:Delete[] function:

adminClient.query(
  q.Delete(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: 1631728043380000,
  role: 'admin',
  hashed_secret: '$2a$05$kdsBSqgV/EoShNny0aoCMuccN94tHSqJOuTTbJ58SRIrHixS/MUhm',
  data: { team: 'Engineering' }
}
result = adminClient.query(
  q.delete(q.ref(q.keys(), "1"))
)
print(result)
{'ref': Ref(id=1, collection=Ref(id=keys)), 'ts': 1631728104560000, 'role': 'admin', 'hashed_secret': '$2a$05$Lo9hpVwalRvyIFbhIZbgy.Y/PEoDjAM/5RzQiVmJoJuiVic5kr/IK', 'data': {'team': 'Engineering'}}
result, err := adminClient.Query(
	f.Delete(f.Ref(f.Keys(), "1")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[team:Engineering] hashed_secret:$2a$05$6APJkVtuIG9nrNzsfnLt4e.D.wVqCLK6sQU2GkqOWov4dSrScgaXK ref:{1 0xc00009b860 0xc00009b860 <nil>} role:admin ts:1631728147980000]
try
{
    Value result = await adminClient.Query(
        Delete(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(1631728225420000),role: StringV(admin),hashed_secret: StringV($2a$05$W5HR2L6lJQ/fLllyqpvVw.knusY0BqHVYztLznZsBF8lvXqGNCE/S),data: ObjectV(team: StringV(Engineering)))
Delete(Ref(Keys(), '1'))
{
  ref: Ref(Keys(), "1"),
  ts: 1631727967280000,
  role: 'admin',
  hashed_secret: '$2a$05$qbGb.Xk0N.7Dnu9LP6MF7up7bgAlR1RiJyyZ4zaRXT521OWwL0Sam',
  data: { team: 'Engineering' }
}
Query metrics:
  •    bytesIn:    41

  •   bytesOut:   222

  • computeOps:     1

  •    readOps:     0

  •   writeOps:     1

  •  readBytes:   285

  • writeBytes:   352

  •  queryTime: 329ms

  •    retries:     0

Discussion

Once a key has been deleted, any client still using the key’s secret can no longer execute queries.

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!