【发布时间】:2016-04-14 02:09:55
【问题描述】:
注意:我不相信这个问题is a duplicate of this similar question,因为它更具体。
我正在尝试使用 nodejs-mongodb-driver 从 Mongo 检索多个对象,并将这些对象作为 JSON 写入 HTTP 响应。对象应该是数组的形式,但由于内存开销,我不想在光标上调用toArray(),我尽量避免大的JSON.stringify 调用。
var response = ... // an http response
collection.find().stream(JSON.stringify).pipe(response); // causes a malformed JSON string
浏览器中的对象如下所示。
{"obj", "obj"}{"obj", "obj"} // clearly malformed
有没有有效的方法来做到这一点?
【问题讨论】:
标签: json node.js mongodb httpresponse