MongoDB通过嵌套数据进行选择

时间:2012-03-29 19:10:01

标签: mongodb

我正在尝试查询MongoDB中的嵌套数据。

理想情况下,我想运行类似于以下的查询:

SELECT FROM attributes.type1 WHERE value = true

我知道我可以使用dot notation按attributes.type1进行查询,但是可以查询比这更深的查询吗?

谢谢!

我的数据集:

{
    "attributes": {
        "type1": [
            {
                "year": "2012",
                "value": "true"
            },
            {
                "year": "1998",
                "value": "false"
            }
        ],
   }
}

1 个答案:

答案 0 :(得分:12)

是的,您可以db.collection.find({"attributes.type1.year": 2012})查询 或者使用高级查询,例如:db.collection.find({"attributes.type1.year": {$lt: 2000}})

这是你的意思吗?