Async.each 抛出错误 [英] Async.each throwing error

查看:30
本文介绍了Async.each 抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,我想更新我的数据库,因此必须使用 async 但它抛出以下错误-TypeError:cb 不是函数.在 E:\smart-in-ffa\apis\node_modules\mongojs\lib\collection.js:106:7在 handleCallback (E:\smart-in-ffa\apis\node_modules\mongojs\node_modules\mongodb\lib\utils.js:96:56)在 E:\smart-in-ffa\apis\node_modules\mongojs\node_modules\mongodb\lib\collection.js:1048:5在 E:\smart-in-ffa\apis\node_modules\mongojs\node_modules\mongodb\node_modules\mongodb-core\lib\connection\pool.js:455:18在 _combinedTickCallback (internal/process/next_tick.js:67:7)在 process._tickCallback (internal/process/next_tick.js:98:9)[nodemon] 应用程序崩溃 - 在启动之前等待文件更改..."

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..."

下面是我的代码:

 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);
            }
    });

推荐答案

这不是给您错误的 async.each 而是 Mongoose 因为您传递了太多参数应该是一个函数是一个对象.

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.

改变这个:

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

为此:

{ upsert: true, multi: true },

这篇关于Async.each 抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆