Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Get number of user posts and his comments count

in my DB collection I have the following documents structure: { owner: ObjectId, counter: number }. As a side note, this is a state I've reached to using aggregate on my real documents. So basically owner is of ObjectId type, and counter fields reporesents a counter.

My target is, given an input x of type ObjectId, to count how many times x presents as an owner (this would be easily achieved by using the $count pipe stage), but also overall sum of counters.

For example, consider the following documents and given id input owner = 1:

{ owner: 1, counter: 20 }, { owner: 2, counter: 10 }, { owner: 3, counter: 2 }, { owner: 1, counter: 5 },

Then, my target is to get a final aggregation result of: { numberOfBeingOwner: 2, overallSumCounter: 20+10+2+5 }

How can I do it using the aggregation pipeline?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!