1 Commits

Author SHA1 Message Date
Pierre THIERRY
a558f09fb4 Add generics functions to mongo class. 2020-09-05 13:01:05 +02:00

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;