Ask coding questions

← Back to all posts
How to get every repl.it database key with a certain value?
beatsnationyt (0)

I'm in need of a way to find every key with a certain value in repl.it. Node.js isn't my strongsuit and I cannot find any other articles related to this.

Answered by AlexDaCoder (21) [earned 5 cycles]
View Answer
Comments
hotnewtop
AlexDaCoder (21)

Since you said "with", I'm assuming it's includes, and you'll need .match instead of ===.

db.list().then(keys => {
  let keysFiltered = keys.filter(k => k.match(/<whatever>/i)); // i for case insensitive, remove the i for case sensitive
});
Coder100 (18915)

You can use the prefix to get every key with a prefix. Beyond this, you could just use a loop:

db.list().then(keys => {
  let keysFiltered = keys.filter(k => k == "<whatever>");
});