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的格式是:spa

"UUID" : [ 
        {
            "id" : "xxxxxx",
            "name" : "HUAWEI DUK-AL20"
        }
    ],
相關文章
相關標籤/搜索