https://i.sstatic.net/pi6js.pngI'm currently in the process of developing a small personal betting website. I have successfully created Arrays of ObjectId's within each collection that reference one another. However, I am facing challenges when it comes to retrieving the items from these collections and displaying them on the view pages. Can someone guide me on how to retrieve more than just the ObjectId's and pass the actual items? I've been exploring the use of .populate(), is this the recommended approach? And if so, how can I access users along with the information from the guess schema, which references the match schema?
//route//
router.get("/:id", function(req, res){
User.findById(req.params.id)
.populate("guess")
.exec(function(err,foundUser){
if(err){
console.log(err);
} else {
res.render("users/show",{user:foundUser});
}
});
});
-----------------------
//viewPage//
<%user.guessList.forEach(function(guess){%>
<div> <%= guess %></div> //need items of this guesses
<% }) %>
------------------
Attached are schemas as shown in the picture.