开发者社区> 问答> 正文

爬虫中mongodb聚合中$group的使用方法是什么?

爬虫中mongodb聚合中$group的使用方法是什么?

展开
收起
游客5n3d3br4o5qn4 2021-11-18 23:55:08 441 0
1 条回答
写回答
取消 提交回答
  • 分组

    db.stu.aggregate( {KaTeX parse error: Expected '}', got 'EOF' at end of input: group:{_id:"hometown",count:{KaTeX parse error: Expected 'EOF', got '}' at position 6: sum:1}̲,total_age:{sum:“KaTeX parse error: Expected 'EOF', got '}' at position 5: age"}̲,avg_age:{avg:”$age"}}} )

    _id分组的依据

    $age 取age对应的值

    $sum:1 把每条数据作为1进行统计,统计的是个数

    s u m : " sum:"sum:"age" 统计年龄对应的和

    $group对应的字典中的键是输出数据的键

    不分组

    db.stu.aggregate( {KaTeX parse error: Expected '}', got 'EOF' at end of input: …id:null,count:{sum:1}}} )

    按照一个字段分组 db.col.aggregate( {KaTeX parse error: Expected '}', got 'EOF' at end of input: group:{_id:"gender",count:{KaTeX parse error: Expected 'EOF', got '}' at position 6: sum:1}̲}} ) 按照多个…group:{_id:{gender:“g e n d e r " , h o m e t o w n : " gender",hometown:"gender",hometown:"hometown”},count:{KaTeX parse error: Expected 'EOF', got '}' at position 6: sum:1}̲}} ) 不分组,…group:{_id:null,count:{$sum:1}}} ) KaTeX parse error: Expected '}', got 'EOF' at end of input: …ggregate( {group:{_id:“KaTeX parse error: Expected '}', got 'EOF' at end of input: gender",name:{push:”$name"}}} )

    2021-11-18 23:55:42
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
开源数据库 MongoDB 专场 MongoDB疑难杂症分析及优化 立即下载
MongoDB多数据中心的方案选型之路 立即下载
Python第五讲——关于爬虫如何做js逆向的思路 立即下载