app.get("/cart", isLoggedIn, async function(req, res){
var cartsretrieved = [];
for(var i = 0; i < req.user.cart.length; i++){
Product.findById(req.user.cart[i]._id, function(err, product){
if(err){
req.flash("error", "An Error has occured, Please try again later.");
return res.redirect("/");
}
else if(i == req.user.cart.length - 1){
return res.render("cart", {product: cartsretrieved});
}
cartsretrieved.push(product);
});
}
});
I am trying to make it easier on the db instead of storing every element with all it's objects i stored the id only and when i need the objects i store it to an array and render it but the code down isn't working so how can i make it thanks for reading