【问题标题】:Maximum call stack size exceeded in mongodbmongodb 中超出了最大调用堆栈大小
【发布时间】:2016-11-03 18:22:41
【问题描述】:

我只是在调用一个方法。

调用方法

var message = "Hello"
     function1("78945612387", message, null, "Portalsms")

节点 JS 代码

 function function1(mobileno,body,logExtraInfo,messageType){
            request(uri, function (error, response, body) {
                if (response) {
                    db.collection.insertOne(getObjectToSave(uri, mobileno, msg, logExtraInfo, messageType, error, response), function (err, result) {
                        if (err) {
                                 console.log(err);
                            //  res.status(400).send(err);
                            return;
                        }
                        console.log(result);
                    });
                }
    }


function getObjectToSave(uri, mobileno, msg, logExtraInfo, messageType, error, response) {


        return {
            "uri" : uri,
            "mobileNo" : mobileno,
            "message" : msg,
            "logExtraInfo" : logExtraInfo,
            "messageType"  : messageType,
            "error"    : error,
            "response" : response,
            "creationDate": new Date()    
        }

}

我不知道为什么它给我这个错误。

(超出最大调用堆栈大小)

我没有递归调用这个函数。

我的请求调用是用于发送短信,在响应之后我只想将结果存储在我的 mongodb 文档“smsLog”中。

我在这里没有使用任何承诺,因为我希望此方法异步运行。

提前感谢

【问题讨论】:

    标签: javascript node.js mongodb express


    【解决方案1】:

    问题可以通过以下方式解决:

    1. 不要使用模式实例进行插入
    2. 使用普通的旧 JSON 对象

    另请参阅StackOverflow Q/A

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-02
      • 2016-09-26
      • 1970-01-01
      • 2017-07-02
      • 2013-08-23
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多