my database structure is something like this:
model of messages in db
each documnet has "receiverNumbers" field with "Object" type:
receiverNumbers: {
type: [{type: Object}],
required: true
},
in this object, we have tow properties. "phoneNumber" and "resultSend" witch resultSend is an object that have few properties.
how can I get the length of receiverNumbers of all documents that the "send" property of "resultSend" object is true?
I know that I should use aggregate but I’m confused how.
2
Answers
Considering that your input documents look like this :
And that you want for each document the number of element in receiverNumbers where element.resultSend.send is true.
You could do something like this :
You can check https://mongoplayground.net/p/crlKjIcmcWR for test.
Let me know if that answers your issue.
You can try something like this: