2016-04-29 16 views
1

私はストリームを初めて使用しており、reactive-superglue/highland.js(https://github.com/santillaner/reactive-superglue)を使用して自分のコレクションからデータを取得しようとしています。ストリーム/ highland.jsを使用した結果からmongodbからデータを取得できません

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/ 
+1

hiiiiiiiiii dave :) – timolawl

答えて

0

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); 
}); 
0

私は、これが最善の方法であるかどうかわからこのアプローチを使用してペイロードを取得できませんでした、非常に他の提案や説明をいただければ幸いです。

exports.findAll = function (err, res) { 
    query.find() 
     .map(JSON.stringify) 
     .toArray(function(x){ 
      res.end(x + '') 
     }) 
} 
1

あなたhighland.jsの.done()は結果を返さないため、コードスニペットは機能しません。 Stream.eachを使用して各要素を反復するか、Stream.toArrayを使用してすべてを配列として取得する必要があります。

私は反応性スーパーグルーの作者です。反応性のスーパーグルーは私の(作業中の)ハイランドのストリームの実際の使用を取る、高地の上に構築されています.js

乾杯!

関連する問題