Stream from a mongodb cursor to Express response in node.js
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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=req.params.tag; console.log('got tag ' + tag + '.'); catalog.byTag(tag,function(err,cursor) { if(err) { console.dir(err); res.end(err); } else { res.writeHead(200, { 'Content-Type': 'application/json'}); //this crashes cursor.stream().pipe(res); } }); }); As you probably guessed, catalog.byTag(tag, callback) does a find() query to Mongodb and returns the cursor This leads to an error: