mongodb在数组中使用聚合

时间:2018-10-19 01:27:05

标签: mongodb join aggregate

过去三天学习MongoDB,我正在尝试汇总2个集合,但无法实现。

菜单

{
"_id" : ObjectId("5bc82eecf74ba34be6c3efef"),
"shop_id" : "777",
"update_dtm" : "",
"menus" : [ 
    {
        "id" : ObjectId("5bc834b5170ae66f26669081"),
        "name" : "pizza",
        "img_url" : "",
        "is_top" : false,
        "comment" : "",
        "order_num" : null,
        "items" : [ 
            {
                "id" : ObjectId("5bc8389e015e5786660c947c"),
                "name" : "special pizza",
                "is_soldout" : false,
                "price" : 15,
                "comment" : "",
                "discount_per" : 0,
                "discount_price" : 0,
                "sale_cnt" : 0,
                "order_num" : 0,
                "options" : [ 
                   "5bc84f2032f67d0cb0d8e49d"
                ]
            }
        ]
    }
]
};

菜单类别和菜单

菜单选项

{
"_id" : ObjectId("5bc84f2032f67d0cb0d8e49e"),
"shop_id" : "777",
"update_dtm" : "",
"options" : [ 
    {
        "id" : ObjectId("5bc84f2032f67d0cb0d8e49d"),
        "name" : "choice dough",
        "img_url" : null,
        "is_stop" : false,
        "is_essential" : true,
        "comment" : "",
        "order_num" : 0,
        "items" : [ 
            {
                "id" : ObjectId("5bc84fb2dcdd1c10253c8f84"),
                "name" : "R Size",
                "img_url" : null,
                "is_soldout" : false,
                "price" : 0,
                "comment" : null,
                "order_num" : 0
            }, 
            {
                "id" : ObjectId("5bc84fddaa9148116718258f"),
                "name" : "L Size",
                "img_url" : null,
                "is_soldout" : false,
                "price" : 2000,
                "comment" : null,
                "order_num" : 0
            }
        ]
    }
]
}

菜单选项类别和选项

预期产量

{
"_id" : ObjectId("5bc82eecf74ba34be6c3efef"),
"shop_id" : "777",
"update_dtm" : "",
"menus" : [ 
    {
        "id" : ObjectId("5bc834b5170ae66f26669081"),
        "name" : "pizza",
        "img_url" : "",
        "is_top" : false,
        "comment" : "",
        "order_num" : null,
        "items" : [ 
            {
                "id" : ObjectId("5bc8389e015e5786660c947c"),
                "name" : "special pizza",
                "is_soldout" : false,
                "price" : 15,
                "comment" : "",
                "discount_per" : 0,
                "discount_price" : 0,
                "sale_cnt" : 0,
                "order_num" : 0,
                "options" : [ 
                    {
                        "id" : ObjectId("5bc84f2032f67d0cb0d8e49d"),
                        "name" : "choice dough",
                        "img_url" : null,
                        "is_stop" : false,
                        "is_essential" : true,
                        "comment" : "",
                        "order_num" : 0,
                        "items" : [ 
                            {
                                "id" : ObjectId("5bc84fb2dcdd1c10253c8f84"),
                                "name" : "R Size",
                                "img_url" : null,
                                "is_soldout" : false,
                                "price" : 0,
                                "comment" : null,
                                "order_num" : 0
                            }, 
                            {
                                "id" : ObjectId("5bc84fddaa9148116718258f"),
                                "name" : "L Size",
                                "img_url" : null,
                                "is_soldout" : false,
                                "price" : 2000,
                                "comment" : null,
                                "order_num" : 0
                            }
                        ]
                    }
                ]
            }
        ]
    }
]
}

菜单选项类别和选项 谁能帮我解决这个问题, 这对我非常有帮助。

0 个答案:

没有答案