目前,当我卷曲到我的端点时,我能够检索到响应,但只能检索一次。对我的服务器的任何其他请求都会触发stream error: Stream already being consumed, you must either fork() or observe()
.
我的堆栈:node、express、highlandjs、mongodb。
//server.js
app.get('/queries', query.calculateTotal);
//我的端点函数
var _ = require('lodash')
var sg = require("reactive-superglue")
var query = sg.mongodb("mongodb://localhost:27017/qatrackerdb").collection("test1")
exports.calculateTotal = function (err, res) {
query.find()
.collect()
.map(function(x) {
console.log(x)
return _.size(x)
})
.apply(function(x) {
return res.status(200).json(x)
})
}
第二次尝试到达我的端点后的服务器响应: curl -i -X GET http://localhost:3000/queries/
GET /queries/ 200 34.442 ms - 632
GET /queries/ - - ms - -
GET /queries/ 500 2.371 ms - 1998
Error: Stream already being consumed, you must either fork() or observe()
at Stream._addConsumer