Skip to main content
Deno.Kv.prototype.list - Deno documentation
method Deno.Kv.prototype.list
Kv.prototype.list<T = unknown>(
selector: KvListSelector,
options?: KvListOptions,
): KvListIterator<T>

Retrieve a list of keys in the database. The returned list is an Deno.KvListIterator which can be used to iterate over the entries in the database.

Each list operation must specify a selector which is used to specify the range of keys to return. The selector can either be a prefix selector, or a range selector:

  • A prefix selector selects all keys that start with the given prefix of key parts. For example, the selector ["users"] will select all keys that start with the prefix ["users"], such as ["users", "alice"] and ["users", "bob"]. Note that you can not partially match a key part, so the selector ["users", "a"] will not match the key ["users", "alice"]. A prefix selector may specify a start key that is used to skip over keys that are lexicographically less than the start key.
  • A range selector selects all keys that are lexicographically between the given start and end keys (including the start, and excluding the end). For example, the selector ["users", "a"], ["users", "n"] will select all keys that start with the prefix ["users"] and have a second key part that is lexicographically between a and n, such as ["users", "alice"], ["users", "bob"], and ["users", "mike"], but not ["users", "noa"] or ["users", "zoe"].
const db = await Deno.openKv();
const entries = db.list({ prefix: ["users"] });
for await (const entry of entries) {
  entry.key; // ["users", "alice"]
  entry.value; // { name: "Alice" }
  entry.versionstamp; // "00000000000000010000"
}

The options argument can be used to specify additional options for the list operation. See the documentation for Deno.KvListOptions for more information.

Type Parameters

T = unknown

Parameters

selector: KvListSelector
optional
options: KvListOptions

Return Type

Back to top