Having an issue utilizing the mongodb query result in another query. Here's some code for reference (inside an async function) - Pay attention to how I'm using created_comment._id in the second query:
let created_comment = await Comment.create(new_comment, (err, newReturnedComment)=>{
if(err){
console.log(err);
}
});
await User.findOneAndUpdate({_id: req.user._id},{ $addToSet: {commentsIds: created_comment._id} },
function(err, updated_user) {
if (err) {
console.log(err);
}
});
Despite using await in the first query, when trying to access the created_comment variable, it returns nothing. Could this be because create and findOneAndUpdate are not promises? Any suggestions on the best practice for performing such queries in a nodejs backend would be greatly appreciated. Thank you.