Thursday, 3 October 2013

mongodb complex query on nested array

mongodb complex query on nested array

I have a single document in MongoDb whose structure is something like this
.. NESTED ARRAY. I want to $addToSet into d:["x","y"] to make it
d:["x","y","z"].
I have tried out $elemMatch and $. But they only work at a SINGLE LEVEL of
array.
{
id:1,
a:[
{
id:2,
b:[
{
id:3,
c:[
{
id:4,
d:["x","y"]
},
{
id:5,
d:["p","q"]
}
]
},
{
id:13,
c:[
{
id:14,
d:["w","q"]
},
{
id:15,
d:["i","j"]
}
]
}
]
}
]
}
What will be the query to get d:["x","y","z"] where query part could be ..
{id:1, "a.id":2, "a.b.id":3, "a.b.c.id":4 } or may be using $elemMatch ?

No comments:

Post a Comment