La forma más fácil es usar un Cursor
(referencia
):
var cursor = db.collection('test').find();
// Execute the each command, triggers for each document
cursor.each(function(err, item) {
// If the item is null then the cursor is exhausted/empty and closed
if(item == null) {
db.close(); // you may not want to close the DB if you have more code....
return;
}
// otherwise, do something with the item
});
Si necesita hacer muchos cálculos, puede considerar si Map-Reduce (referencia ) se ajustaría a sus necesidades, ya que el código se ejecutaría en el servidor de base de datos, en lugar de localmente.