• mongodb 中查询子分类的数量


    数据结构大概是这样的:

    {
        "_id" : ObjectId("5cbd9384ec422c7a39cfb4d4"),
        "city" : [ 
            {
                "count" : NumberLong(1),
                "rank" : NumberLong(1),
                "score" : NumberLong(0),
                "tagid" : "北京",
                "tagone" : "0",
                "tagthree" : "0",
                "tagtwo" : "0",
                "tagtype" : NumberLong(5),
                "username" : "v2716770"
            }
        ],
        "industry" : [],
        "power" : [ 
            {
                "count" : NumberLong(100),
                "rank" : NumberLong(1),
                "score" : NumberLong(10000000),
                "tagid" : "5",
                "tagone" : "0",
                "tagthree" : "0",
                "tagtwo" : "0",
                "tagtype" : NumberLong(4),
                "username" : "v2716770"
            }, 
            {
                "count" : NumberLong(1),
                "rank" : NumberLong(2),
                "score" : NumberLong(8),
                "tagid" : "2",
                "tagone" : "0",
                "tagthree" : "0",
                "tagtwo" : "0",
                "tagtype" : NumberLong(4),
                "username" : "v2716770"
            }
        ],
        "produline" : [ 
            {
                "count" : NumberLong(1),
                "rank" : NumberLong(1),
                "score" : NumberLong(8),
                "tagid" : "3",
                "tagone" : "0",
                "tagthree" : "0",
                "tagtwo" : "0",
                "tagtype" : NumberLong(3),
                "username" : "v2716770"
            }
        ],
        "tenet" : [],
        "username" : "v2716770"
    }

     查询每个子分类下的数组长度;

    db.taguser.aggregate(
        { "$project" : {
            "username" : 1 ,
            "tenet" : {$size:"$tenet"}, 
            "industry" : {$size:"$industry"}, 
            "power" : {$size:"$power"}, 
            "produline" : {$size:"$produline"}, 
            "city" : {$size:"$city"}, 
        }}
     )

    查询出的结果是这样的:

  • 相关阅读:
    jQuery
    编程英语
    Javaweb基础案例
    Maven-基础设置教程
    .Net微服务实践(三):Ocelot配置路由和请求聚合
    .Net微服务实践(二):Ocelot介绍和快速开始
    ASP.NET Core技术研究-探秘Host主机启动过程
    Docker安装手册
    HBase文档学习顺序
    考研学习笔记极限与连续笔记顺序
  • 原文地址:https://www.cnblogs.com/tong775131501/p/12384346.html
Copyright © 2020-2023  润新知