0

我很难为这个问题选择正确的标题。我有如下文件和子文件列表

{
        "name" : "Pets",
        "subcategories" : [
            {
                "name" : "Cats",
                "fbCategories" : []
            },
            {
                "name" : "Dogs",
                "fbCategories" : []
            }
        ],
        "fbCategories" : ["Pet Services","Pet Supplies", "Animal"]
    },
    {
        "name" : "Entertainment",
        "subcategories" : [
            {
                "name" : "Music",
                "subcategories" : [
                    {
                        "name" : "Albums",
                        "fbCategories" : [ "Album"]
                    },
                    {
                        "name" : "Musicians",
                        "fbCategories" : ["Concert Tour","Musician/Band"]
                    }
                ],
                "fbCategories" : [
                    "Concert Venue",
                    "Music Chart",
                    "Music Video",
                    "Musical Instrument",
                    "Record Label",
                    "Music"
                ]
            }

在此示例中,我们有两个主要类别(“宠物”、“娱乐”)及其对应的子类别(“宠物”的猫和狗,...)。虽然有不同级别的子类别,但所有文档/子文档都有两个键,name 和 fbCategories。我想在不编写循环或多个查询的情况下找到每个类别/子类别的 fbCategories。无论如何要在一个查询中查询它们,结果应该列出每个 “名称”键的“fbCategories” 。例如对于“音乐家” ,它将列出,而对于“音乐”,它将列出["Concert Tour","Musician/Band"]

 ["Concert Venue","Music Chart","Music Video","Musical Instrument","Record Label","Music"]          
4

1 回答 1

0

看看:在 mongodb 中查找嵌入文档?

没有循环,恕我直言,这个问题没有解决方案,因为 $where 语句在聚合框架中受到限制。

于 2013-04-19T21:19:39.700 回答