下面是我的代码,我想更新我的数据库,因此必须使用异步但它抛出以下错误 - “TypeError:cb不是函数 . 在E:\ smart-in-ffa \ apis \ node_modules \ mongojs \ lib \ collection.js:106:7 at handleCallback(E:\ smart-in-ffa \ apis \ node_modules \ mongojs \ node_modules \ mongodb \ lib \ utils.js:96:56)位于E:\ smart-in-ffa \位于E:\ smart-in-ffa \ apis \ node_modules \ mongojs \ node_modules \ mongodb \ node_modules \ mongodb-core \ lib \ connection \ pool的apis \ node_modules \ mongojs \ node_modules \ mongodb \ lib \ collection.js:1048:5 .js:455:18在_combinedTickCallback(internal / process / next_tick.js:67:7)at process._tickCallback(internal / process / next_tick.js:98:9)[nodemon] app崩溃 - 在开始之前等待文件更改......”
以下是我的代码:
async.each(jsondata,
function(itemdata, callbackNew){
//console.log(item);
db.mdb.collection('Copy_of_counters')
.update(
{"store_code":itemdata.store_code},{$set:itemdata},
{ upsert: true },{ multi: true },
function (erreach, data) {
if (erreach) {
console.log("error reported")
console.log(erreach)
callbackNew(erreach);
}
else{
console.log('Data updated')
callbackNew();
//app.send(req,res,data);
}
})
},function(err){
if(err) {
console.log("this is the error"+err)
app.senderr(req,res,err);
}
else{
app.send(req,res,jsondata);
}
});
1 回答
这不是
async.each
,它给你的错误,但它是Mongoose,因为你传递了太多的参数,应该是一个函数的是一个对象 .改变这个:
对此: