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

318
Views
Count the number of items with a condition in MongoDB collection

I can't figure out what I'm doing wrong with my query. I want to get the number of "alertes" with the field "resolved: false" so my query is :

Alertes.find({resolved: false}).count();

But it returns me 0 despite I have 1 entry in the collection with the field resolved: false

Somone could help me to figure out what I'm doing wrong ?

enter image description here

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

I had forgot to subscribe to the collection in my IronRouter file :

Router.route('/', {
  name: 'home',
  waitOn: function() {
    return [
      Meteor.subscribe('infosContainers'),
      Meteor.subscribe('infosMachines'),
      Meteor.subscribe('alertes'),
    ];
  },
  fastRender: true,
});

Thank you for the help

over 4 years ago · Santiago Trujillo Report

0

Did you try this?

Alertes.find({resolved: false}).fecth().length

If you are running this code at the client side, make sure you have subscribed to this collection, and that you have documents that satisfy the filter you are looking for. Try to query all documents (with no filter) to make sure the documents are there with the query above, and check what you get back:

Alertes.find().fecth()

If you don't find any documents with the resolved property set to false, then the query is returning correctly, and the problem is your subscription.

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!