2014년 12월 28일 일요일

[mongoose] Re: How can I count the number of all documents in a Collection using Mongoose?

if you want to count a all users in users try
users.count({}, function(err, result){
});
or you can chain it after a find
users.find().count(function(err, count){
});

On Wednesday, July 16, 2014 11:40:54 AM UTC-4, dessa beca GP wrote:
I am trying to count all Documents in a Collection but I just get 'undefined '.

I searched in  Mongoose Documentation but the only example that I have is this :

 users.count(query , function(err, result){
      
if(err) ...
// count is the result
 
var count = result
      
});

 So, in Mongoose Documentation I can count the number of documents that match a query passed in the function, but

How can I count all the Documents in a Collection? All without any query? 

In Mongoose terminal I can just do :

db.CollectionName.count()

Does someone know how to do it using Mongoose? 

Thank you.

-- 
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs


댓글 없음:

댓글 쓰기