MongoDB SELECT COUNT GROUP BY

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

    This would be the easier way to do it using aggregate:

    db.contest.aggregate([
        {"$group" : {_id:"$province", count:{$sum:1}}}
    ])
    

提交回复
热议问题