Memory leaks when iterating over mongo data stream using NodeJS Memory leaks when iterating over mongo data stream using NodeJS mongoose mongoose

Memory leaks when iterating over mongo data stream using NodeJS


Try setting a batchSize instead of pausing the stream yourself.

var stream = Schema.find().batchSize(50).stream();


I suspect leak may be in your code. You use doc in internal callback closure.Try to tell GC doc is not necessary anymore after it is saved.

OtherSchema.find().exec(function(err,others) {   doc.total = others.data + doc.data;   doc.save(function(err) {     written++;   });   doc = null;//tell GC to free doc  });