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

254
Views
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
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!