Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to findAll in mongoosejs?

My code is like that:

SiteModel.find(     {},     function(docs) {         next(null, { data: docs });     } ); 

but it never returns anything... but if I specify something in the {} then there is one record. so, how to findall?

like image 295
murvinlai Avatar asked Aug 30 '11 17:08

murvinlai


People also ask

How do you get all the mongoose?

Now, to get all users list from the mongoose collection you have to call User. find() with an empty object as the first parameter. It will search for all the documents that match with the filter Object. But when you pass an empty filter, it will match with all the documents and will return all documents.

What does find () return in mongoose?

find() function returns an instance of Mongoose's Query class. The Query class represents a raw CRUD operation that you may send to MongoDB. It provides a chainable interface for building up more sophisticated queries.

What is $in in mongoose?

The value of the $in operator is an array that contains few values. The document will be matched where the value of the breed field matches any one of the values inside the array.

How do you use mongoose findOne?

Mongoose | findOne() FunctionThe findOne() function is used to find one document according to the condition. If multiple documents match the condition, then it returns the first document satisfying the condition. Installation of mongoose module: You can visit the link to Install mongoose module.


1 Answers

Try this code to debug:

SiteModel.find({}, function(err, docs) {     if (!err) {          console.log(docs);         process.exit();     }     else {         throw err;     } }); 
like image 194
pepo Avatar answered Oct 04 '22 11:10

pepo