In the controller, it searches the countries
collection for all countries. Inside db.db.collection ....
I have console.log (countries)
. It works because the terminal returns me all countries. But res.json (countries)
doesn't work. On the client side, it returns to me data: ''
. How can I put the content returned by return countries
in res.json()
?
//controllers/countries
module.exports.read = (req, res) => {
const countries = db.db.collection('countries').findOne({}, function (findErr, countries) {
if (findErr) throw findErr;
console.log(countries); //it works, in terminal return me all countries
return countries;
});
res.json(countries);
};