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

243
Views
Meteor - Mongo aggregate does not have $count stage

I am using meteorhacks:aggregate package to do Mongo aggregation in Meteor. I want to get the count at the last stage of the pipeline so I use this code:

Message.aggregate([
  {
    $match: {
      // ...
    }
  }, {
    $count: 'count'
  }
]);

It is pretty simple and should work, but I only get this error:

Exception while invoking method 'methodname' 
MongoError: Unrecognized pipeline stage name: '$count'
...

Please help, thanks.

Updated: this question is not duplicated as an editor suggested, my main intention is to find out why I can not use $count

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

$count is available in mongodb version 3.4. For previous versions, you will need to use $group over a constant field.

Message.aggregate([
  {
    $match: {
      // ...
    }
  }, {
    $group: {
      _id : null, 
      count : {$sum : 1}
    }
  }
]);
over 4 years ago · Santiago Trujillo Report
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!