I have a JSON like this, I want to count by status false JSON img
{
"chats": [
{
"memberId": "ff9e28ec-4f6f-42e2-9e66-43b888267fe5",
"messages": [
{
"messagesId": "54174c03-c669-44fb-872a-75ff5c52166f",
"user": {
"userId": "4dd8495a-5704-435d-bee2-6b474e25cbbf",
"name": "Event",
"profilePicture": "png"
},
"createdAt": "",
"title": "belajar",
"image": "minio.png",
"messages": "belajar",
"status": false
}
]
}
]
}
I want to get the count of all messages where status is false.
Example
{
"memberId" : "ff9e28ec-4f6f-42e2-9e66-43b888267fe5"
"statusCount" : 2
}
messagesarray with astatusoffalse? You can't do this with a normal query. You'll need to use the aggregation pipeline, using$unwindto get individual messages and then perform the count manually (e.g. use$groupwith the$sumoperator).