MongoDB:如何在对象结构深处获取具有特定属性的文档?

时间:2014-02-16 16:28:16

标签: php mongodb

如何从RockMongo和PHP获取具有“test”:NumberInt(1000)属性的MongoDB文档?

我尝试了类似 {“items”:{“test”:1000}} ,但是

  

找不到记录。

Mongo集合示例:

{
   "_id": ObjectId("xxx"),
   "items": {
     "0": {
       "0": {
         "test": NumberInt(1000)
        }
      },
       "1": {
         "test": NumberInt(2000)
        },
    },
},
{
   "_id": ObjectId("yyy"),
   "items": {
     "0": {
       "0": {
         "test": NumberInt(3000)
        }
      },
       "1": {
         "test": NumberInt(4000)
        },
    }
}

1 个答案:

答案 0 :(得分:1)

试试这个

db.coll.find( { 'items.test': 1000 } )

并确保itemsarray而不是object