Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb wrong return from Mycollection.find().count();

i have a problem with my app. When written this db.request.count(); on mongo shell i have 4, but when i written Request.find().count() in my js code i have 0. Someone can help me ?

like image 573
Lyès SARDI Avatar asked Dec 20 '25 16:12

Lyès SARDI


2 Answers

Try using Request.count() instead of calling count() after find().

This is assuming the name of your model is Request.

The Mongoose documentation has examples here.

like image 74
Frank Matranga Avatar answered Dec 22 '25 07:12

Frank Matranga


If you ran Request.find().count() on the client and got 0, it's most likely that your client-side code did not subscribe to the Request collection.

If you ran Request.find().count() on the server and got 0, make sure you connected to the correct database. I.e. Meteor creates its own Mongo instance on port 3001, whilst you may have been using a different database on 27017.

like image 24
d4nyll Avatar answered Dec 22 '25 09:12

d4nyll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!