I have a mongo document collection like the following, I'm trying to find the documents which has images for all the colors in that document also the document template should not be empty.
[
{
"template" : "one",
"colors" : [
{
"name" : "yellow",
images : ["img_one", "image_two"]
},
{
"name" : "blue",
images : ["img_one", "image_two"]
}
]
},
{
"template" : "",
"colors" : [
{
"name" : "green",
images : ["img_one", "image_two"]
},
{
"name" : "orange",
images : ["img_one", "image_two"]
}
]
},
{
"template" : "three",
"colors" : [
{
"name" : "green",
images : ["img_one", "image_two"]
},
{
"name" : "orange",
images : []
}
]
}
]
I tried the following query but it's not working.
db.getCollection('my_products').find({
"template": {$ne : ""},
"colors": {
$all: [
{
"$elemMatch": {"images": {$not : {$size : 0}}}
}
]
}
});
What I can do to get something like that?