当前位置: 首页 > 后端技术 > Python

mongodb查询唯一数据项出现次数,排序

时间:2023-03-26 16:38:32 Python

列出唯一数据项db.getCollection('records').aggregate([{$match:{is_job:true}},])按指定字段统计.getCollection('records').aggregate([{$match:{is_job:true}},{$group:{_id:"$gname",count:{$sum:1}}},])在组中定义数据返回的字段现在有id(id表示为主键)和count字段按指定字段排序db.getCollection('records').aggregate([{$match:{is_job:true}},{$group:{_id:"$gname",count:{$sum:1}}},{$sort:{count:-1}}])延伸阅读MongoDB统计唯一数据分组https://blog.csdn.net/weixin_...MongoDB的skip,limit,sortexecutionorder,andaggregatehttps://blog.csdn.net/jason_c...