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?

Thank!

My dataset:

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

      

+3


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?

+12


source







All Articles