Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda