开发者社区 问答 正文

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

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

展开
收起
游客5n3d3br4o5qn4 2021-11-18 23:55:08 464 分享
分享
版权
举报
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 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等