mongodb数据分组按字符串split


db.getCollection('users').aggregate([
    {$match:{ZWBH:11}},
    {$unwind:'$UUID'},
    {$project : { PM : { $split: ["$UUID.name", " "] } } },
    {$project: {PM:{ $arrayElemAt: [ "$PM", 0 ]}}},
    {$project: {PM:{ $toLower: "$PM"}}},
    {$group:{_id:'$PM',sum:{$sum:1}}},
     {$sort:{sum:-1}}
])

分组用户所用的手机品牌数量,其中UUID的格式是:

"UUID" : [ 
        {
            "id" : "xxxxxx",
            "name" : "HUAWEI DUK-AL20"
        }
    ],

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM