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

264
Visualizações
How to retreive all records by month/year with mongoose?

I want to filter a collection to retreive X records, giving a specific month, filter the field "CreatedAt", by month.

const aggregatorOpts = [
    {
      $group: {
        _id: "$userId",
        count: { $sum: 1 }
      }
    }, {
      $addFields: {
        "month": {
          $month: '$createdAt'
        }
      }
    }, {
      $match: {
        month: 1 //want to pass the month where
      }
    }]

  const result = await Something.aggregate(aggregatorOpts).sort({ count: -1 }).exec()

The code above is what i already tried out.

Im also grouping by user with more occurrences in the collection, and sorting by that. Is it possible to filter by month as i want, in mongoose?

about 4 years ago · Juan Pablo Isaza
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