0

I'm stuck with a MongoDB collection that looks like below. I want to query for documents that match flag: true and match if any object below bar matches value: "v_b".

As I fail to understand how to query past bar's array and had no luck using aggregation, I'd be grateful for an example – thanks a lot.

{
    "flag": true,
    "foo" : {
        "name" : "dont care",
        "bar" : [
            {
                "a" : {
                    "name": "n_a",
                    "value" : "v_a"
                },
                "b" : {
                    "name": "n_b",
                    "value" : "v_b"
                },
                "c" : {
                    "name": "n_c",
                    "value" : "v_c"
                }
            }
        ]
    }
},
{
    "flag": false,
    "foo" : { ... }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
0xPIT
  • 26
  • 2
  • 1
    This way it looks that you have not stuck but have not started to try anything. – Salvador Dali Nov 19 '13 at 18:17
  • I think it cannot be done as stated [here](http://stackoverflow.com/questions/6790819/searching-for-value-of-any-field-in-mongodb-without-explicitly-naming-it)... As I see, you should rethink your modeling. – Vitor Tyburski Apr 09 '14 at 19:59
  • I agree, it is in need of remodelling. However that's not an option currently. Hm, I thought it might be with Mongo's array comprehension, like the first answer in the question you linked. (e.g. something like `db.mydb.find({'foo.bar.a.value':'v_a'})`) – 0xPIT Apr 11 '14 at 08:26

0 Answers0