I have created an employee attendance application where attendances are logged and stored in a database. I have tried to obtain a count of all date-field with the value of
If you want to find by property in embedded document you have to use dot notation
this will not work, because you are asking mongoo to find the document which have attendances object equal the same given object.
{ "attendances": {"2019-08-26": "Present"}}
this will work only if attendances object in your database contains only
{ "attendances": {"2019-08-26": "Present"}}
that's mean that you asking mongoo if the stored object is equal the given object and it will return false
{ "attendances": {"2019-08-26": "Present" , "2019-08-27": "Sick"}} == { "attendances": {"2019-08-26": "Present"}}
to do this you have to use dot notation
Employee.collection.countDocuments({"attendances.2019-08-26":"Present"},(err,data)=>{
if(err){
res.status(500)
res.send(err)
}else{
res.status(200)
res.json(data)
}
})