0

I have a collection like the following

array(

'Pinned' => 
  array (
    '0' => 
    array (
      'PageId' => '511b6b482284a5481d000000',
      'PageTitle' => 'VOIP Business',
    ),
    '1' => 
    array (
      'PageId' => '511b6b482284a5481d000001',
      'PageTitle' => 'Dialers',
    ),
  ),
  'ReportAbuse' => 0,

)

"Pinned" can contain multiple arrays inside it. I need find those documents that have

'PageId' => '511b6b482284a5481d000000'

inside Pinned.

So i tried

'Pinned' => array(
      'PageId' => '511b6b482284a5481d000000'
)

But i didn't work. I hope my question is clear :). Please help me if any one knows the answer. Thanks.

4

2 回答 2

0

目前仅顶级数组支持查询和操作数组元素,嵌套数组不支持 - 请参阅http://docs.mongodb.org/manual/reference/operator/positional/中的 $ position 运算符

这可能会在未来发生变化,请参阅https://jira.mongodb.org/browse/SERVER-831

同时,嵌套数组的查询和更新必须在客户端完成:

  • 将文档读入变量
  • 操作数组
  • 更新文档,重写整个数组
于 2013-04-03T20:57:06.417 回答
0

You need your language's equivalent of :

find({'Pinned.PageId': '511b6b482284a5481d000000'})

Note that this only works for the top level array.

于 2013-03-12T11:44:54.200 回答