foobar
foobar4w ago

KV multimap / unordered keys search

Hello, I want to do an unordered keys search on deno kv FoundationDB talk about multimap (https://apple.github.io/foundationdb/multimaps.html ). I don't find it for deno kv.
// deno run --unstable-kv test.ts

const kv = await Deno.openKv();

let res = await kv.set(["users", "alex", "foot"], "alex foot");
console.log(res)
res = await kv.set(["users", "alex", "basket"], "alex basket");
console.log(res)
res = await kv.set(["users", "alex", "tennis"], "alex tennis");
console.log(res)

// just want users and basket without alex
// => don't work
const iter = kv.list<string>({ prefix: ["users", "basket"] });
// this work
// const iter = kv.list<string>({ prefix: ["users","alex"] });
const users = [];
for await (const res of iter) users.push(res);
console.log(users[0]);

kv.close()
// deno run --unstable-kv test.ts

const kv = await Deno.openKv();

let res = await kv.set(["users", "alex", "foot"], "alex foot");
console.log(res)
res = await kv.set(["users", "alex", "basket"], "alex basket");
console.log(res)
res = await kv.set(["users", "alex", "tennis"], "alex tennis");
console.log(res)

// just want users and basket without alex
// => don't work
const iter = kv.list<string>({ prefix: ["users", "basket"] });
// this work
// const iter = kv.list<string>({ prefix: ["users","alex"] });
const users = [];
for await (const res of iter) users.push(res);
console.log(users[0]);

kv.close()
No description
4 Replies
Evan
Evan4w ago
what do you mean unordered? do you mean arbitrarily ordered?
foobar
foobar4w ago
in my example, I want to get all keys including ["users", "basket"]or ["basket", "users"], ie I don't care for orders. kv only authorises strict prefix, here only ["users","alex"] works In a real usecase, I want to filter on some criteria (country, city, sport...)
Evan
Evan4w ago
the article you shared is unrelated to the behavior you want this is something you can achieve by creating your own secondary indices
foobar
foobar4w ago
the code example shows that you can't do it with prefix, only if your criterias meet exactly your key