how to use aggregate function in meteor

前端 未结 4 1271
悲哀的现实
悲哀的现实 2020-12-07 01:46

I\'m working on the following document

{
\"_id\" : 12,
\"firstName\" : \"wer\",
\"People\" : [ 
    {
        \"uuid\" : \"123\",
        \"name\" : \"sugun\         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-07 02:19

    I used the meteorhacks:aggregate package. It works only on the server side.

    meteor add meteorhacks:aggregate

    MyCollection.aggregate({ 
      $match: { 
        propertyToQuery: 'valueForProperty' 
      }, { 
        $group: {
          _id: '$propertyToGroupBy',
          result: { $operation: '$propertyToPerformOperationOn' }
        }
    });
    

    https://github.com/meteorhacks/meteor-aggregate https://themeteorchef.com/snippets/aggregations-in-mongodb/

提交回复
热议问题