我对流很陌生,我正在尝试使用reactive/Highland.js (https://github.com/santillaner/reactive-superglue)从我的集合中获取数据。
var sg = require("reactive-superglue")
var query = sg.mongodb("mongodb://localhost:27017/qatrackerdb").collection("test1")
exports.findAll = function (err, res) {
query.find()
.map(JSON.stringify)
.done(function(data) {
console.log(data)
res.end(data)
})
}我的卷发请求:
curl -i -X GET http://localhost:3000/queries/发布于 2016-06-14 04:23:52
我不太清楚reactive-superglue在这里为你做了什么。看起来,这只是一个高地快捷键的汇编,以获得不同数据源的响应。
您可以使用高地直接这样做:
var collection = sg.mongodb("mongodb://localhost:27017/qatrackerdb").collection("test1");
return h( collection.find({}) )
.map(h.extend({foo: "bar"})
.pipe(res);编辑:上面的代码片段仍然使用reactive-superglue,但是您可以只使用节点mongo驱动程序:
var url = 'mongodb://localhost:27017/qatrackerdb';
MongoClient.connect(url, function(err, db) {
h( db.collection("test1").find({}) )
.map(h.extend({foo: "bar"})
.pipe(res);
});发布于 2016-10-26 07:26:55
您的代码片段无法工作,因为Highland.js的.done()不返回结果。您应该使用Stream.each来迭代每个元素,或者使用Stream.toArray将它们作为数组来获得。
顺便说一句,我是反应型强力胶的作者。反应-强力胶是我的(正在进行中的工作)采取的实际使用高地的流,建立在highland.js之上。
干杯!
发布于 2016-04-29 20:40:49
我能够使用这种方法检索有效载荷,不确定这是否是最好的方法,将非常感谢任何其他建议或解释。
exports.findAll = function (err, res) {
query.find()
.map(JSON.stringify)
.toArray(function(x){
res.end(x + '')
})
}https://stackoverflow.com/questions/36945468
复制相似问题