mongoose full collection scan mongoose full collection scan mongoose mongoose

mongoose full collection scan


Your first option should be to use the aggregate method instead of find to do whatever aggregation you're looking to do. If that doesn't do what you need, look into mapReduce, like you mentioned.

However, if you find that you do need to iterate over a large collection, you should use Mongoose's support for streaming the result of the query rather than getting it in one big array.

var stream = MyModel.find().stream();stream.on('data', function (doc) {  // do something with the mongoose document}).on('error', function (err) {  // handle the error}).on('close', function () {  // the stream is closed});