There is one element "imageNames" in my MongoDB collection which is sometimes having an empty value, how to get the count of the no of times it is having empty value as well as no of times it is non-empty.
[
{
"_id":{"$oid":"5ce2391c076c4e65d7d6789c"},
"lotDetails":{
"produce":"aaa",
"variety":"default",
"type":"default",
"defects":"default"
},
"imageNames":[],
},
{
"_id":{"$oid":"5ce2391c076c4e65d7d4563c"},
"lotDetails":{
"produce":"aaa",
"variety":"mixed",
"type":"default",
"defects":"default"
},
"imageNames":[
{
"_id":{"$oid":"5ce2537222295a7bc66354346a"},
"username":"reshmap222",
"userData":[
{
"comments":[],
"_id":{"$oid":"5ce2537222295a7bc657857b"},
"imageName":"11-aaa-868187035222222-1548314329957.jpg",
"state":"pending",
"imageDate":{"$date":{"$numberLong":"1555744370501"}}
}
]
}
]
},
{
"_id":{"$oid":"5ce2391c076c4e65d7d2345c"},
"lotDetails":{
"produce":"aaa",
"variety":"mixed",
"type":"default",
"defects":"default",
},
"imageNames":[]
},
{
"_id":{"$oid":"5ce2391c076c4e65d7d8792c"},
"lotDetails":{
"produce":"aaa",
"variety":"default",
"type":"default",
"defects":"default",
},
"imageNames":[
{
"_id":{"$oid":"5ce2537222295a7bc657857a"},
"username":"reshmap222",
"userData":[
{
"comments":[],
"_id":{"$oid":"5ce2537222295a7bc657857b"},
"imageName":"11-aaa-868187035111111-1548314329957.jpg",
"state":"pending",
"imageDate":{"$date":{"$numberLong":"1555744370501"}}
}
]
}
]
},
{
"_id":{"$oid":"5ce2391c076c4e65d7d3233c"},
"lotDetails":{
"produce":"aaa",
"variety":"mixed",
"type":"default",
"defects":"default",
},
"imageNames":[],
}
]
Expected result : [
{variety :"mixed",empty : 2, not-empty: 1},
{variety :"default",empty : 1, not-empty: 1}
]
I have the produce name coming from front end to find the elements,here we can take the produce name as "aaa" for $match.