Search code examples
mongodbmongoose

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?


Solution

  • Try this code to debug:

    SiteModel.find({}, function(err, docs) {
        if (!err) { 
            console.log(docs);
            process.exit();
        }
        else {
            throw err;
        }
    });