I'm trying to update a field in my nested array to change the "phone" number. Below is my function:
module.exports.checkIn = async(req, res) => {
const idNum = req.body.guest;
Event.findOneAndUpdate({"_id": req.params.id, "guests._id": idNum }, {phone: 22222 }, (error, data) => {
if(error){
res.send(error);
} else {
res.send(data);
}
});
}
For context, req.body.guest = 1234objectidnumberwithoutquotes5678
Here is my Event model:
const eventSchema = new Schema({
address: String,
description: String,
guests: [
{
phone: Number,
attended: String
}
],
});
I'm not getting any errors but the phone number isn't updating. What am I missing? Have been combing through the mongoose docs and youtube and can't figure it out.