Answer the question
In order to leave comments, you need to log in
How to overcome callback hell in nodejs+mongodb? Can you help me understand where to dig in search of errors?
The bottom line is - I'm trying to write a simple database patch with the following code:
exports.checkVersion = function(serverVersion){
MongoClient.connect(mn.path(), function(error, database){
if (!error) {
database.collection('params').findOne({"name": "version"}, function(err,version){
var i = 0;
if(!err && version && version.value) {
if(serverVersion > version.value) {
for (i = version.value; i <= serverVersion; ++i){
var patch = require('./patches/'+i+'_patch.js');
patch.execPatch(database, i, function(err){
console.log(err);
});
}
}
}
else {
for (i = 0; i <= serverVersion; i++){
var patch = require('./patches/'+i+'_patch.js');
patch.execPatch(database, i, function(err){
console.log(err);
});
}
}
})
}
else { console.dir(error); }
});
};
exports.execPatch = function(database, serverVersion, callback){
database.collection('params').insert({"name":"version","value":serverVersion},function(err){callback(err);});
...ну и ещё пара идентичных операций...
}
/home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/connection/base.js:245
throw message;
^
TypeError: undefined is not a function
at /home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/db.js:1000:14
at /home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/db.js:445:7
at /home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/cursor.js:163:16
at commandHandler (/home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/cursor.js:709:16)
at /home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/db.js:1846:9
at Server.Base._callHandler (/home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/connection/base.js:445:41)
at /home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/connection/server.js:478:18
at MongoReply.parseBody (/home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/home/m0sk1t/WebStormProjects/project/node_modules/mongodb/lib/mongodb/connection/server.js:436:20)
at EventEmitter.emit (events.js:95:17)
Answer the question
In order to leave comments, you need to log in
Beat the idiot and send him on vacation ... I figured it out =) It was in another section of the code, I
changed it to
database.collection('allMarks',function(err, allMarks){allMarks.update(...);}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question