这里的其他答案的工作组合
app.get('/comments', (req, res) => { Comment.find() .cursor() .pipe(JSONStream.stringify()) .pipe(res.type('json'))})http://mongoosejs.com/docs/api.html#query_Query-
cursor
cursor()
返回与Node stream3兼容的流,并且该流优先于不推荐使用的query.stream()
接口。- 通过管道
JSONStream.stringify()
将文档组合成数组而不是单个对象 res.type('json')将HTTPContent-Type
标头设置为的管道application/json
并再次返回自身(响应流)。



