开发者

PHP MongoDB find nested element

How can I do a select for all documents that have a parent.id that is equal to 3? I t开发者_运维百科ry doing this.parents.id == 3, but it doesn't seem to be working...

[parents] => Array (
    [0] => Array (
        [id] => 1
        [title] => Folder 1
    )
    [1] => Array (
        [id] => 3
        [title] => Folder 2
    )
)


OK, so the PHP input is actually unclear. The PHP you provided could be one of the following JSON objects:

Version 1:

{ parents: 
  [ 
    { id: 1, title: "Folder 1" }, 
    { id: 3, title: "Folder 2" } 
  ] }

Version 2:

{ parents: 
  { 0: { id: 1, title: "Folder 1" }, 
    1: { id: 3, title: "Folder 2" } 
} }

If you do find({'parents.id':3}) on version 1, this will work.

If you do find({'parents.id':3}) on version 2, this will not work.

The difference is not clear in PHP, so use the command-line and double-check.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜