This is my code snippet, I want to return all the data on the Products collection but I can’t get the data but when I use x.findOne() method to query the db, I get the last data in the collection. Please help me out on this.
app.get('/api/willsolar/products/getall', async(req, res) => {
try {
await productDataBase.find({}, (err, products) => {
if(err) {
console.log(err)
} else {
console.log(products);
// console.log(products);
// please I need help on how to figure out the problem of get request for all items here
// this only consoles the last item on the collection, but I want all to be consolled.
return res.json({msg: 'found items'});
}
})
} catch (error) {
console.log(error)
}
});
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.