MongoDB SELECT COUNT GROUP BY

后端 未结 7 2284
不知归路
不知归路 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:49

    Additionally if you need to restrict the grouping you can use:

    db.events.aggregate( 
        {$match: {province: "ON"}},
        {$group: {_id: "$date", number: {$sum: 1}}}  
    )
    

提交回复
热议问题