cleanup of mongo wrapper

This commit is contained in:
Erik 2022-11-13 21:11:12 +02:00
parent 7da9adf8a5
commit 426b22489b
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -84,20 +84,9 @@ class MongoDB {
* @returns {Object} An object containing the queried data * @returns {Object} An object containing the queried data
* @memberof Database * @memberof Database
*/ */
async findOne (db, query, options) { async findOne (db, query, options = {}) {
this.logger.debug(`Incoming findOne query for ${db} with parameters ${JSON.stringify(query)}`); this.logger.debug(`Incoming findOne query for ${db} with parameters ${JSON.stringify(query)}`);
// return new Promise((resolve, reject) => {
// this.db.collection(db).findOne(query, async (error, item) => {
// if (error) return reject(error);
// return resolve(item);
// });
// });
const result = await this.db.collection(db).findOne(query, options); const result = await this.db.collection(db).findOne(query, options);
return result; return result;
@ -116,16 +105,6 @@ class MongoDB {
this.logger.debug(`Incoming update query for '${db}' with parameters\n${JSON.stringify(filter)}\nand data\n${JSON.stringify(data)}`); this.logger.debug(`Incoming update query for '${db}' with parameters\n${JSON.stringify(filter)}\nand data\n${JSON.stringify(data)}`);
if (!filter) throw new Error(`Cannot run update many without a filter, if you mean to update every single document, pass an empty object`); if (!filter) throw new Error(`Cannot run update many without a filter, if you mean to update every single document, pass an empty object`);
// this.logger.warn('Database.update() is deprecated!');
// return new Promise((resolve, reject) => {
// this.db.collection(db).updateMany(filter, data, async (error, result) => {
// if (error) return reject(error);
// return resolve(result);
// });
// });
const result = await this.db.collection(db).updateMany(filter, { $set: data }, { upsert }); const result = await this.db.collection(db).updateMany(filter, { $set: data }, { upsert });
return result; return result;
@ -143,20 +122,6 @@ class MongoDB {
async updateOne (db, filter, data, upsert = false) { async updateOne (db, filter, data, upsert = false) {
this.logger.debug(`Incoming updateOne query for ${db} with parameters ${JSON.stringify(filter)}`); this.logger.debug(`Incoming updateOne query for ${db} with parameters ${JSON.stringify(filter)}`);
// return new Promise((resolve, reject) => {
// this.db.collection(db).updateOne(filter, { $set: data }, { upsert }, async (error, result) => {
// if (error) return reject(error);
// // return resolve(result)
// const { matchedCount, upsertedCount, modifiedCount } = result;
// return resolve({ matched: matchedCount, upserted: upsertedCount, modified: modifiedCount });
// });
// });
const result = await this.db.collection(db).updateOne(filter, { $set: data }, { upsert }); const result = await this.db.collection(db).updateOne(filter, { $set: data }, { upsert });
return result; return result;
@ -175,17 +140,6 @@ class MongoDB {
async push (db, filter, data, upsert = false) { async push (db, filter, data, upsert = false) {
this.logger.debug(`Incoming push query for ${db}, with upsert ${upsert} and with parameters ${JSON.stringify(filter)} and data ${JSON.stringify(data)}`); this.logger.debug(`Incoming push query for ${db}, with upsert ${upsert} and with parameters ${JSON.stringify(filter)} and data ${JSON.stringify(data)}`);
// return new Promise((resolve, reject) => {
// this.db.collection(db).updateOne(filter, { $push: data }, { upsert }, async (error, result) => {
// if (error) return reject(error);
// return resolve(result);
// });
// });
const result = await this.db.collection(db).updateOne(filter, { $push: data }, { upsert }); const result = await this.db.collection(db).updateOne(filter, { $push: data }, { upsert });
return result; return result;