The problem I am facing is below:
I have a MongoDB document whose structure is as follows
"name": "XYZ",
"array":[
{
"value": "Alpha"
},
{
"value": "Beta"
},
{
"value": "Alpha"
},
]
and I have to count how many objects have value Alpha. I have tried the following two queries but both only give me value 1.
db.current_database.find({array: {$elemMatch: {value: "Alpha"}}}).count()
db.current_database.find({'array.value': 'Alpha'}).count()