dbdjs.mongo
Version:
MongoDB wrapper using mongoose with dbdjs.db-like API
21 lines (13 loc) • 525 B
JavaScript
async function all({ _, models }, name, { filter } = {}) {
const model = models.get(name);
if (!model) throw new Error(`No model with name '${name}' found`);
if (typeof filter !== "function") return [];
const cursor = model.find({}).lean().cursor();
const filtered = [];
for (let doc = await cursor.next(); doc != null; doc = await cursor.next()) {
const x = { key: doc.key, data: { key: doc.key, value: doc.data } };
if (filter(x)) filtered.push(x);
}
return filtered;
}
module.exports = all;