0
votes

Wanted to test the speed of inserting new documents in the database mongodb, However, when the amount of insertion is very large, it returns the following error: "RangeError: Maximum call stack size exceeded" Can anyone tell me why I get the message?

var counters2Schema = new mongoose.Schema({'_id': ObjectId, 'seq':String}, { versionKey: false, collection: 'counters'  }),

var k = 100000;
testCUPwrite function (i) {
     var MyObjectId = mongoose.Types.ObjectId;
     MyObjectId = new MyObjectId();
     var counters2Model = new mongoose.model("counters", counters2Schema);
     new counters2Model({'seq': MyObjectId}). save ();
     console.log ('teste_' + MyObjectId);
     if (i <k) {
         i + +;
         setTimeout (testCUPwrite (i), 1);
     }

}
testCUPwrite (0);

Thank you

1

1 Answers

0
votes

This line:

setTimeout (testCUPwrite (i), 1);

is not doing what you think it is. That's directly executing the testCPUWrite function in the current stack. It's not using setTimeout like you think. Something like

setTimeout(testCUPwrite.bind(null, i), 1);

Might get you going.