与一个嵌套字段分组,并查找其他嵌套字段

时间:2018-08-10 06:26:44

标签: mongodb aggregation-framework

我是mongodb的新手,我想与嵌套字段组合在一起,并且还希望其他字段的结果

我的文档在下面:

 {
    "venueId" : "4cd55465dfb4a1cd3954585c"
    "restaurantcompetitors" : [
        {
            "id" : ObjectId("5b6ae9c8d7ef00445c8fa637"),
            "userid" : "5b67d22916cb5c0f9c0b0f26",
            "username" : " rohit kumar",
            "competitorName" : "Zomato",
        },
        {
            "id" : ObjectId("5b6ae9cbd7ef00445c8fa671"),
            "userid" : "5b67d22916cb5c0f9c0b0f26",
            "username" : " rohit kumar",
            "competitorName" : "estet",
            "competitorNote" : "",
        },
        ]
}



I want to group by with 
"restaurantcompetitors.competitorName" but also i need to 
project other fields of  "restaurantcompetitors" array

like i want fields of

restaurantcompetitors.id, 
restaurantcompetitors.userid, 
restaurantcompetitors.username, etc.

有人可以帮我吗

谢谢。

0 个答案:

没有答案