Below are the three collections i am referencing in the topic
-
Tags:
{“id”:909,“name”:“newTag”} -
contacts
{“id":1,“name”,“testcontact”,“email”:"test@test.com”,“tags”:[]}
–tags field contaains list of References of linked tags collection document -
Campaign:
{“id”:1,“name”,“testcampaign”,“tags”:[]}
–tags field contaains list of References of linked tags collection document
Objective is to get list of all tags ,with the Count of Contacts & Campaigns who are referencing that particular tag.
I want to understand the best practice to do that through aggregation which is scalable and responds quickly as i am only interested in count of other collections.
An Example Result would be
[
{“id”:909,“name”:“newTag”,“campaignCount”:2,“contactCount”:5},
{“id”:909,“name”:“newTag”,“campaignCount”:0,“contactCount”:10}
]