Michael FrancisM
Denoβ€’2y ago
Michael Francis

KV watch prefix?

Is there a way to watch a prefix.

I would like to be able to watch for any record added to a specific key prefix.
export async function logData(jsonObject: Object) {
  const timestamp = Date.now();
  const id = nanoid();
  try {
    console.log("set", timestamp, id);
    await kv.set(["dev-logs", timestamp, id], jsonObject);
    console.log("done set");
  } catch (error) {
    console.error(error);
  }
}


I want to be able to
const newLogs = kv.watch([["dev-logs]])

And now I have an iterator that I can watch any new logs added.
Was this page helpful?