From 426b22489bef13dd1a6cca3827383b4a104aad36 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 13 Nov 2022 21:11:12 +0200 Subject: [PATCH] cleanup of mongo wrapper --- src/server/database/MongoDB.js | 48 +--------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/src/server/database/MongoDB.js b/src/server/database/MongoDB.js index cbcb4f7..a35abe0 100644 --- a/src/server/database/MongoDB.js +++ b/src/server/database/MongoDB.js @@ -84,20 +84,9 @@ class MongoDB { * @returns {Object} An object containing the queried data * @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)}`); - // 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); 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)}`); 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 }); return result; @@ -143,20 +122,6 @@ class MongoDB { async updateOne (db, filter, data, upsert = false) { 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 }); return result; @@ -175,17 +140,6 @@ class MongoDB { 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)}`); - // 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 }); return result;