MongoDB SELECT COUNT GROUP BY

后端 未结 7 2177
不知归路
不知归路 2020-11-22 15:24

I am playing around with MongoDB trying to figure out how to do a simple

SELECT province, COUNT(*) FROM contest GROUP BY province

But I can

7条回答
  •  隐瞒了意图╮
    2020-11-22 15:38

    If you need multiple columns to group by, follow this model. Here I am conducting a count by status and type:

      db.BusinessProcess.aggregate({
        "$group": {
            _id: {
                status: "$status",
                type: "$type"
            },
            count: {
                $sum: 1
            }
        }
       })
    

提交回复
热议问题