JSFiddle - React, Tailwind, and code Playground
by somekittens
JavaScript
function getCollection(coll, callback) {
mdb.open(function(err, db) {
db.collection(coll, callback);
});
}
function cleanup(next) {
return function() {
//Gives me an error here
//ReferenceError: db is not defined
//Even though db will be defined where the function is executed
db.close();
if(typeof next === 'function') {
next();
}
};
}
function error(err, db) {
if(err) {
console.error(err);
db.close();
}
}
module.exports = {
insert: function(coll, query, next) {
getCollection(coll, function(err, collection) {
collection.insert(query, cleanup(next));
});
},