简体   繁体   中英

Maximum call stack size exceeded in mongodb

I am just calling a method.

Calling method

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

Node JS Code

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

}

I dont know why its giving me this error.

(Maximum call stack size exceeded )

I am not calling this function recursively.

My request call is for sending the sms,after the response i just want to store the result in my mongodb document "smsLog".

I am not using any promise here because i want this method to run asynchronous.

Thanx in advance

The problem can be resolved by:

  1. Don't use a schema instance for the insert
  2. Use a plain old JSON object

See also this StackOverflow Q/A .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM