Add generics functions to mongo class.
This commit is contained in:
16
mongo.js
16
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;
|
||||
Reference in New Issue
Block a user