Async.each throwing error

会有一股神秘感。 提交于 2019-12-12 03:58:51

问题


Below is my code and I want to update my DB and thus have to use async but it is throwing following error-"TypeError: cb is not a function. at 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) at E:\smart-in-ffa\apis\node_modules\mongojs\node_modules\mongodb\lib\collection.js:1048:5 at E:\smart-in-ffa\apis\node_modules\mongojs\node_modules\mongodb\node_modules\mongodb-core\lib\connection\pool.js:455:18 at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9) [nodemon] app crashed - waiting for file changes before starting..."

Below is my code :

 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:


This is not async.each that is giving you the error but it's Mongoose because you are passing too many parameters and the one that should be a function is an object.

Change this:

{ upsert: true },{ multi: true },

to this:

{ upsert: true, multi: true },


来源:https://stackoverflow.com/questions/42528312/async-each-throwing-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!