I currently have a Message schema which has a sub-document of replies as such:
message: String,
replies: [{
message: String,
userFrom: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}]
I am attempting to make a POST request that will allow me to findOneAndUpdate the message to attach a reply. I've attempted the following:
Message.findOneAndUpdate(req.params.id,{
replies: {
message: req.body.reply,
userFrom: req.user._id
}
}, function(err, data){
...
});
What is happening is I am overwriting any reply that is currently in the replies array. I believe I need to use the $push operator but I'm not quite sure how.
Is it possible to use findOneAndUpdate as well as $push in a single request?
Thanks for such a great article here.
RépondreSupprimerMern stack online training
Mern stack training in hyderabadv
Thank you for the help you have given for me.
RépondreSupprimerFull Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course