key.delete()

Learn: Keys

Delete a key.

Signature

delete() => NullKey

Description

Deletes a key, represented as a Key document.

A key is a type of authentication secret used for anonymous access to a Fauna database. Unlike tokens, keys are not associated with an identity.

Parameters

None

Return value

Type Description

NullKey

Document doesn’t exist. See NullDoc.

Examples

Basic example

Key.byId("412655134325080576")!.delete()
Key("412655134325080576") /* deleted */

Delete all keys

To avoid throttling, you can incrementally delete all keys for a database before deleting the database itself.

To stay within transaction size limits, use set.paginate() to perform the deletions over several queries instead of one.

// Gets all `Key` system collection documents.
// Uses `pageSize()` to limit the page size.
// Uses `paginate()` to project the after cursor.
let page = Key.all().pageSize(200).paginate()

// `paginate()` returns an object. The object's `data` property
// contains an Array of `Key` documents.
let data = page.data

// Use `forEach()` to delete each `Key` document in the
// `data` Array.
data.forEach(doc => doc.delete())

// Project the `after` cursor returned by `paginate()`.
// Use the cursor to iterate through the remaining pages.
page {
  after
}
{
  after: "hdWDxoq..."
}

Subsequent queries use the cursor and Set.paginate() to iterate through the remaining pages:

// Uses `Set.paginate()` to iterate through pages.
let page = Set.paginate("hdW...")

let data = page.data

data.forEach(doc => doc.delete())

page {
  after
}
\