MongoDB select by nested data

I am trying to query embedded data in MongoDB.

Ideally I would like to run a query similar to:

SELECT FROM attributes.type1 WHERE value = true


I understand that I can use dot notation to query on .type1 attributes, but can I query deeper than that?


My dataset:

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



source to share

1 answer

Yes, you can request db.collection.find({"attributes.type1.year": 2012})

or, for example, use advanced queries, such as: db.collection.find({"attributes.type1.year": {$lt: 2000}})


Is this what you mean?



All Articles