From a558f09fb494757dd3a830d730df3a0b060cbe09 Mon Sep 17 00:00:00 2001 From: Pierre THIERRY Date: Sat, 5 Sep 2020 13:01:05 +0200 Subject: [PATCH] Add generics functions to mongo class. --- mongo.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mongo.js b/mongo.js index 204aa97..4eaa64e 100644 --- a/mongo.js +++ b/mongo.js @@ -22,6 +22,22 @@ class Mongo { client.close(); }) } + + insert(collectionName, entity, callback) { + this.db.collection(collectionName).insert(entity, (error, result) => { + assert.equal(null, error, `Unable to insert ${collectionName} entity: ${error}.`); + console.log(`Entity ${collectionName} inserted.`); + callback(result); + }) + } + + update(collectionName, entity, query, callback) { + this.db.collection(collectionName).update(query, entity, (error, result) => { + assert.equal(null, error, `Unable to update ${collectionName} entity: ${error}.`); + console.log(`Entity ${collectionName} updated.`); + callback(result); + }) + } } module.exports = Mongo; \ No newline at end of file