Stream from a mongodb cursor to Express response in node.js

前端 未结 5 1200
死守一世寂寞
死守一世寂寞 2020-11-29 05:12

I am toying around with all the fancy node.js/mongodb/express platforms, and stumbled across a problem:

app.get(\'/tag/:tag\', function(req, res){
  var tag=         


        
5条回答
  •  渐次进展
    2020-11-29 05:55

    Using mongoose and express:

    function(req, res){
        var stream = database.tracks.find({}).stream();
        stream.on('data', function (doc) {
            res.write(JSON.stringify(doc));
        });
        stream.on('end', function() {
            res.end();
        });
    }
    

提交回复
热议问题