Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
每层嵌套的查询MongoDB N层_Mongodb_Nested - Fatal编程技术网

每层嵌套的查询MongoDB N层

每层嵌套的查询MongoDB N层,mongodb,nested,Mongodb,Nested,我在Linux上运行了MongoDB 2.6.1中保存的文档结构: { "_id" : "1", "name" : "Level0", "childs" : [ { "id" : "2", "name" : "Level1", "childs" : [ { "id" : "3",

我在Linux上运行了MongoDB 2.6.1中保存的文档结构:

{
    "_id" : "1",
    "name" : "Level0",
    "childs" : [ 
        {
            "id" : "2",
            "name" : "Level1",
            "childs" : [ 
                {
                    "id" : "3",
                    "name" : "Level2",
                    "childs" : [ 
                        {
                            "id" : "4",
                            "name" : "Level3-1",
                        }, 
                        {
                            "id" : "5",
                            "name" : "Level3-2",
                        }
                    ]
                }
...
每个元素都有自己的孩子,每个子元素都有自己的孩子,直到技术结束

现在,我想用如下方式查询我的MongoDB:

db.categories.find({'childs':{$elemMatch:{$all:['Level19-23']}}})
顺便说一下,这个查询不起作用

什么是获取我的元素的好查询

我对孩子或父母一无所知,我只知道元素的名字,我需要元素和他的所有孩子

有人给我提建议吗,MongoDB新手?:)


提前谢谢

您研究过分层数据存储吗?您可以将元素存储为单独的文档,而不是嵌套元素,但可以将子id存储在父文档中。这使我更容易查询数据。嘿,阿切埃托,我将尝试这样保存我的数据!:)谢谢您。