I am struggling to get the mongodb query working. Below is my example collection. As you can see that the picture List is an optional nested array.
{
"firstName" : "Mark",
"gender" : "M",
"PictureList":[]
},
{
"firstName" : "Jane",
"gender" : "F",
"PictureList":[]
},
{
"firstName" : "Mary",
"gender" : "F",
"PictureList" : [{"name" : "20151128_233939.jpg","dpInd" : "N"},
{"name" : "20150712_231715.jpg","dpInd" : "Y"}
]
}
My Question is? I need to
- select all the records with Gender = "F"
Apply another filter at level 2 to only pull the records from the nested array whose dpInd = "Y". If this condition is not met then show empty results only for nested array. My Expected Results is
{ "firstName" : "Jane", "gender" : "F", "PictureList":[] } { "firstName" : "Mary", "gender" : "F", "PictureList" : [{"name" : "20150712_231715.jpg","dpInd" : "Y"}] }