AndrewLeonardi AndrewLeonardi - 5 months ago 21
Node.js Question

Display Multiple Mongoose Models on one results page

I am needing to display Multiple Mongoose Models on one results page. Here is my current code to get the results page. I have models set up for "Cards" and "Beliefs" but I cannot figure out the syntax to display both. Any thoughts? Thank you!

app.get("/profile", function(req, res){
Cards.find({ "author.username": req.user.username }, function(err, author){
Beliefs.find({"author.username": req.user.username }, function(err, author){
if (err){
console.log(err);
} else {
res.render("done.ejs", {Beliefs: author, Cards: author, currentUser: req.user});
}
});
});
});

Answer

Try using different variable names for author. Belief's callback function argument author is overlapping the author you received from Cards model. Something like beliefsAuthor and cardsAuthor should do.