Add generics functions to mongo class.

This commit is contained in:
Pierre THIERRY
2020-09-05 13:01:05 +02:00
parent e794e65942
commit a558f09fb4

View File

@@ -22,6 +22,22 @@ class Mongo {
client.close(); 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; module.exports = Mongo;