Is my interpretation correct? Is there a way to do this?
It seems by my reading of other posts and the Mongoose doc, the newly created document can only be truly displayed as populated after it's saved to the database.
This behaviour seems fair enough to preserve data consistency, but there seems to be a lot of overhead in firstly ceating, then saving, then retrieving it then populating it then displaying the new object.
My code is inside a router.js file, to wit:
if(favorites == null) {
var newFavorite = new Favorites({
postedBy: req.decoded._doc._id,
dishes: req.params.dishId
});
newFavorite.save(function(err) {
if(err) throw err;
console.log('Favo created!');
//pseudocode below-------------------------------------------
newFavorite
.populate('postedBy')//I need to populate this..
.populate('dishes')//and this so I can show the referenced docs in their entirety in the response which is...
.exec(function (err, user) {
//handle error
})
//pseudocode above-------------------------------------------
res.json(newFavorite)//---populated object here!
;
});
} else {