Mongoose - RangeError: Maximum Call Stack Size Exceeded

后端 未结 7 2242
遇见更好的自我
遇见更好的自我 2020-12-08 14:38

I am trying to bulk insert documents into MongoDB (so bypassing Mongoose and using the native driver instead as Mongoose doesn\'t support bulk insert of an array of document

7条回答
  •  粉色の甜心
    2020-12-08 15:07

    I have faced similar issue.

    //manyvalues is array of objects
    schema.methods.somemethod = function(manyvalues,callback) {
        this.model(collection).collection.insertMany(manyvalues,callback);
    }
    

    But this caused error [RangeError: Maximum call stack size exceeded]. So I have created new model from manyvalues and used it as below and it worked.

    schema.methods.somemethod = function(manyvalues,callback){
         var list = JSON.parse(JSON.stringify(manyvalues));//created a new object.
         this.model(collection).collection.insertMany(list,callback);
    }
    

    The problem may be caused if manyvalues is changed internally.

提交回复
热议问题