Node.js, Express, MongoDB and streams Node.js, Express, MongoDB and streams mongodb mongodb

Node.js, Express, MongoDB and streams


This writes to res every time there's data to write:

var stream = collection.find({'day_timestamp':{'$gte':from, '$lte':to}})    .sort({day_timestamp:1})    .stream();stream.on('data', function(data) {  res.write(JSON.stringify(data));});stream.on('end', function() {  res.end();});