Javascript 无法使用streams/highland.js从结果中从mongodb获取数据
我是streams的新手,我正在尝试使用reactive superglue/highland.js()从我的收集中获取数据 我的请求:Javascript 无法使用streams/highland.js从结果中从mongodb获取数据,javascript,node.js,mongodb,rest,highland.js,Javascript,Node.js,Mongodb,Rest,Highland.js,我是streams的新手,我正在尝试使用reactive superglue/highland.js()从我的收集中获取数据 我的请求: curl -i -X GET http://localhost:3000/queries/ 我能够使用这种方法检索有效负载,不确定这是否是最好的方法,如果有任何其他建议或解释,我将不胜感激 exports.findAll = function (err, res) { query.find() .map(JSON.stringify)
curl -i -X GET http://localhost:3000/queries/
我能够使用这种方法检索有效负载,不确定这是否是最好的方法,如果有任何其他建议或解释,我将不胜感激
exports.findAll = function (err, res) {
query.find()
.map(JSON.stringify)
.toArray(function(x){
res.end(x + '')
})
}
我真的不确定
反应性超级胶水在这里为您做了什么。看起来它只是一个高地快捷方式的汇编,用于让不同的数据源做出响应
您可以使用highland直接执行以下操作:
var collection = sg.mongodb("mongodb://localhost:27017/qatrackerdb").collection("test1");
return h( collection.find({}) )
.map(h.extend({foo: "bar"})
.pipe(res);
编辑:
上面的代码段仍然使用反应性超级胶水
,但您可以只使用node 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);
});
您的代码段不起作用,因为highland.js的.done()不返回结果。您应该使用Stream.each迭代每个元素,或者使用Stream.toArray将它们全部作为一个数组
顺便说一句,我是反应性强力胶的作者。反应型超级胶水是我在highland.js上构建的highland's streams的真实应用
干杯
var url = 'mongodb://localhost:27017/qatrackerdb';
MongoClient.connect(url, function(err, db) {
h( db.collection("test1").find({}) )
.map(h.extend({foo: "bar"})
.pipe(res);
});