How to findAll in mongoosejs?
const result = await SiteModel.find()
- Without the {}
in the .find()
function works as well.
The 2017 Node 8.5 way
try {
const results = await SiteModel.find({});
console.log(results);
} catch (err) {
throw err;
}
Try this code to debug:
SiteModel.find({}, function(err, docs) {
if (!err) {
console.log(docs);
process.exit();
}
else {
throw err;
}
});
From the documentation:
let result = SiteModel.find({}, function (err, docs) {});
or using async await you can do like this also:
let result = await SiteModel.find({});