Phitiani
Phitiani•16mo ago

Querying multiple documents at once

Hello everyone, I'm sorry I don't have a lot of experience in BE development-- I'm mainly a frontend dev. Is it possible to query a set of documents from the db with the argument being an array of ids rather than just one?
2 Replies
erquhart
erquhart•16mo ago
If you have ids, map over them concurrently. It'll be real fast.
const docs = await Promise.all(ids.map(id => {
return db.get(id)
}))
const docs = await Promise.all(ids.map(id => {
return db.get(id)
}))
I'm sure there's an upper bound here, but I've done this with hundreds of ids without a problem. Also, no need to apologize for being a frontend dev here, I'm the same 🙂
Phitiani
PhitianiOP•16mo ago
Yep, that does the job perfectly. interesting solution. Thank you very much @erquhart!

Did you find this page helpful?