Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • I use the aggregation but these collections are unrelated. Commented Aug 25, 2020 at 21:00
  • What do you mean unrelated? You are getting every user and then getting the poll_votes for each of them in a loop; my suggestion is a single query that gets the poll_votes for every user.
    – domenikk
    Commented Aug 26, 2020 at 9:26
  • I am getting data from 5 different collections. I see your point now - I can get the count for all users at once. This will be more efficient than the current solution where I call this count within a loop for each user separately. I need to think about behaviour when there will be tens of thousands of users and I need five such result sets. Commented Aug 26, 2020 at 9:54