Group (By) in Mongoose?

后端 未结 4 1205
盖世英雄少女心
盖世英雄少女心 2021-02-12 15:18

I\'ve constructed the query I want in the shell but am having trouble writing it in Mongoose.

db.commentstreams.group({ key: { page_id: true }, reduce: function(         


        
4条回答
  •  误落风尘
    2021-02-12 15:42

    I worked with similar example, I hope this be helpful

    Register.aggregate(
    [
      {
       $group: {_id: {campaign: "$campaign"}, quantity: {$sum: 1}}
    },
      {
        $limit: 5
      },
      {
        $sort: {date: -1}
      }
    ], function (err, res) {
            console.log(res)
    });
    

提交回复
热议问题