Mongoose将聚合函数转换为Sequelize

时间:2017-10-02 14:21:47

标签: javascript mongoose sequelize.js

如何将此Mongoose代码转换为Sequelize?

     Model.aggregate()
        .match({
          _deal: this.deal._id
        })
        .group({
          _id: '$tier',
          count: {
            $sum: 1
          }
        })
        .exec()

1 个答案:

答案 0 :(得分:0)

找到解决方案。 也许会帮助某人

Model.findAll({
  where: {
    deal_id: deal.id
  },
  attributes: ['tier', [db.sequelize.fn('count', db.sequelize.col('tier')), 'count']],
  group: ['Model.tier']
})