gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 00:40:46 25 4
gpt4 key购买 nike

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

25 4 0