I am currently working on querying and adding users to a global array from my database. My goal is to store the elements in this global array so that I can access it from any part of my application.
app.get("/admin/orders", (req, res) => {
Quote.find({}, (err, quotes) => {
var products = [];
var users = [];
quotes.forEach((quote) => {
User.findOne({ email: quote.user }, (err, user) => {
if (!err) {
users.push(user);
}
});
});
res.render("orders", { quotes: quotes, users: users, products: products });
});
});
Despite not receiving any errors from the database and successfully retrieving my users, when trying to log the array I am getting an empty result.