Skip to content
← Back to Community
How to get every repl.it database key with a certain value?
Profile icon
beatsnationyt

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 AzureDev [earned 5 cycles]
View Answer
Voters
Profile icon
beatsnationyt
Comments
hotnewtop
Profile icon
AzureDev

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 });
Profile icon
Coder100

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>"); });