可以从Mongodb返回嵌套元素

时间:2011-06-28 17:07:35

标签: mongodb

说我有以下结构:

{
    site : [
        page1:
        {
            title: "Page One",
            content: "Content for page one"
            subpages : [
                {
                    title: "Subpage one",
                    content: "Content for subpage one"
                },
                {
                    title: "Subpage two",
                    content: "Content for subpage two"
                },
                {
                    title: "Subpage three",
                    content: "Content for subpage three"
                }
            ]
        },

        page2:
        {
        ...
        },

        page3:
        {
        ...
        }
    ]
}

我想检索Subpage One的内容,即存储一个大型嵌套结构,并根据xpath样式说明符检索该结构中的特定节点。我也希望能够更新该节点。

the docs,我认为这不可能,但我听说它在哪里。

2 个答案:

答案 0 :(得分:0)

这是不可能的 - 文档是正确的。

答案 1 :(得分:0)

这对你有用吗?

IN: > thing =  { "foo" : "1", "subthing" : {  "bar" : "2",  "subsubthing" : {  "baz" : "3"  }  } }
OUT: {
 "foo" : "1",
 "subthing" : {  "bar" : "2",  "subsubthing" : {  "baz" : "3"  }  }
 }

IN > thing.foo
OUT: "1"

IN: > thing.subthing
OUT: {
 "bar" : "2",
 "subsubthing" : {  "baz" : "3"  }
 }

IN: > thing.subthing.bar
OUT: "2"

IN: > thing.subthing.subsubthing
OUT: {
 "baz" : "3"
 }

IN: > thing.subthing.subsubthing.baz = "4"
"4"
> thing.subthing.subsubthing.baz
"4"