UNPKG

dbdjs.mongo

Version:

MongoDB wrapper using mongoose with dbdjs.db-like API

28 lines (22 loc) 527 B
async function set({ _, models }, name, key, value) { if (typeof key !== "string") throw new TypeError("Invalid key type, expecting string"); const model = models.get(name); if (!model) throw new Error(`No model with name '${name}' found`); const result = await model .findOneAndUpdate( { key: key, }, { key: key, data: value, }, { upsert: true, } ) .catch(() => {}); return typeof result !== undefined; } module.exports = set;