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 database

Reading or writing database documents requires an admin key.

Problem

You need to delete a child database and all of its contents.

Solution

Use the Delete function:

adminClient.query(
  q.Delete(q.Database('llyr'))
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
{
  ref: Database("llyr"),
  ts: 1622573509680000,
  name: 'llyr',
  data: { env: 'test' },
  global_id: 'yoiji573cydyy'
}
result = adminClient.query(
  q.delete(q.database("llyr"))
)
print(result)
{'ref': Ref(id=llyr, collection=Ref(id=databases)), 'ts': 1622573512400000, 'name': 'llyr', 'data': {'env': 'test'}, 'global_id': 'yoijihdqgydyy'}
result, err := adminClient.Query(
	f.Delete(f.Database("llyr")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
map[data:map[env:test] global_id:yoiji3uwcybyy name:llyr ref:{llyr 0xc00009b7d0 0xc00009b7d0 <nil>} ts:1622573473320000]
try
{
    Value result = await client.Query(
        Delete(Database("llyr"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
ObjectV(ref: RefV(id = "llyr", collection = RefV(id = "databases")),ts: LongV(1622573463870000),name: StringV(llyr),data: ObjectV(env: StringV(test)),global_id: StringV(yoijia8e1ybyy))
Delete(Database('llyr'))
{
  ref: Database("llyr"),
  ts: 1624310577730000,
  name: 'llyr',
  data: { env: 'test' },
  global_id: 'yoat8nnggybyy'
}
Query metrics:
  •    bytesIn:   30

  •   bytesOut:  170

  • computeOps:    1

  •    readOps:    0

  •   writeOps:    1

  •  readBytes:  344

  • writeBytes:  491

  •  queryTime: 31ms

  •    retries:    0

Discussion

When a database is deleted, all of the database contents are deleted, including documents, collections, functions, keys, tokens, roles, access providers, and indexes.

It is not possible to delete the parent database, the current database, or any of the current database’s peers using Delete. You can only delete child databases.

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!