Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda