javascript - 无法使用streams/highland.js从结果中从mongodb获取数据

标签 javascript node.js mongodb rest highland.js

我是流新手,我正在尝试使用reactive-superglue/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 请求:

curl -i -X GET http://localhost:3000/queries/

最佳答案

您的代码片段不起作用,因为 highland.js 的 .done() 不返回结果。您应该使用 Stream.each 迭代每个元素,或者使用 Stream.toArray 将它们全部作为数组获取。

顺便说一句,我是reactive-superglue 的作者。 reactive-superglue 是我(正在进行中的)对 highland 流的实际使用的看法,构建在 highland.js 之上

干杯!

关于javascript - 无法使用streams/highland.js从结果中从mongodb获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36945468/

相关文章:

javascript - 可点击的表格单元格,而非行

javascript - ASP.NET/VB.NET : Dropdownlist SelectedIndexChanged not firing with onchange ="javascript:return true;"

javascript - 用于按摩数据的 Angular JS 服务 promise

json - Mongo JSON 文档 -> JSON -> BSON

mongodb - 数据库安装问题 : Binary files folder (bin) is missing in downloaded zip for MongoDB (Windows 64-bit)

node.js - MongoDB 位置附近独特

javascript - 如何在文件输入更改事件中使用循环

javascript - 最成熟的原生 Node.js MySQL 驱动?

node.js - Mongoose,更新对象数组中的值

javascript - 如何在浏览器刷新时加载特定页面