2017-12-27 20 views
0

私は遭遇しましたTypeError:collection.aggregate(...)。カーソルは関数ではありませんループバックv3.8.0、ループバックmongodbコネクタv1 18.1。collection.aggregate(...)。カーソルが関数ループバックmongodb

モデル名の代わりに、以下のようにコレクション名を指定してみました。

var sampleCollection = SampleModel.getDataSource().connector.collection(SampleModel.modelName); 
var data = sampleCollection.aggregate(pipeline).cursor({ batchSize: 1000, async: true }).exec(function(err, cursor){ 
     console.log(cursor); 
}); 
+0

私は '配列、' cursor'は正常動作のためです( 'find') – Khang

+0

@Khangしかし、集約戻っ 'AggregationCursor' ではない '配列' を返しaggregate'覚えています。このエラーがドライバ自体と何か関係があるかどうかは疑問です。 https://github.com/Automattic/mongoose/issues/2306を参照してください。 –

答えて

0
var pipeline = [{ 
     $match: { 
      restaurantId: ObjectID(id) 
     } 
     }, { 
     $project: { 
      'y': { 
      '$year': '$orderDateTime' 
      }, 
      'm': { 
      '$month': '$orderDateTime' 
      }, 
      'd': { 
      '$dayOfMonth': '$orderDateTime' 
      } 
     } 
     }, { 
     $group: { 
      _id: { 
      year: '$y', 
      month: '$m', 
      day: '$d' 
      }, 
      totalRevenue: { 
      '$sum': '$totalBillAmount' 
      } 
     } 
     }]; 
     Model.getDataSource().connector.connect(function(err, db) { 
     var collection = db.collection('model-name'); 
     var cursor = collection.aggregate(pipeline, function(err, results) { 
      console.log(results); 
     }); 
     }); 
関連する問題