2016-12-21 5 views
0

大規模なアグロゲートクエリを使用して、「allowDiskUse:true」をオプションとして渡す必要がありました。これは、ここで説明するように集合関数では機能しません。 https://github.com/meteorhacks/meteor-aggregate/issues/11メソッド内で流星カーソルを待っています

私の流星法はここで定義されています。私がメソッドを呼び出すと、何かがクライアントに返される前にondataが完了するのを待つ必要がありますが、私が試したことは何もないので、フロントエンドまで安全にデータを取得できます。

Meteor.methods({ 
    'getSummary': function (dept,startDate,endDate,filterType) { 

     f = myQuery(startdate,enddate,dayFinalGroup); 
     f.on("data", Meteor.bindEnvironment(function(row) { 
//load an array or something here to return 
      })); 
      f.once("end", Meteor.bindEnvironment(function() { 
       // tidy up, in my case end the stream 

      })); 


    //here I'd return the array loaded 

    }, 

}); 

これは私のフロントエンドです。

Meteor.call(
    'getSummary',0,Session.get('start_date'),Session.get('end_date'),1, 
    function(error, result){ 
     if(error){ 
      console.log(error); 
     } else {   
       Session.set('sumTotals',result); 
     } 
    } 
    ); 

答えて

1

最後に取得しました。私はwrapSyncを利用しました

'getSummary': function (dept,startDate,endDate,filterType) { 
     console.log(dept); 
     console.log(startDate); 
     console.log(endDate); 
     console.log(filterType); 
     var startdate = new Date(startDate); 
     var enddate = new Date(endDate); 
     var arr = []; 
     f = myQuery(startdate,enddate,dayFinalGroup); 

     var fetchCursor = Meteor.wrapAsync(function fetchCursor (cursor, cb) { 

         cursor.each(function (err, doc) { 
         if (err) return cb(err); 
         if (!doc) return cb(null, { done: true }); // no more documents 

         arr.push(doc); 
         }); 
     }); 


    var myData = fetchCursor(f); 




     return arr; 
+1

あなたのメソッドで 'this.unblock()'を忘れないでください。 https://themeteorchef.com/tutorials/using-unblock-and-defer-in-methodsを参照してください –

+0

ありがとう! – VinnieS

関連する問題