I have below object.
{
_id: ObjectId(6082adfaeced28382c167bd7),
inviteMountaineers:
[{
_id: ObjectId(6082c4f9dcfaa86794601058),
userId: ObjectId(60829eb5f1d2c316dfd79cd8),
status:"Invited"
},{
_id: ObjectId(6082c4f9dcfaa86794601055),
userId: ObjectId(60829eb5f1d2c316dfd79cd5),
status:"Invited"
}]
}
I want to update status of invited mountaineers and I tried using below code.
const expedition = await Expedition.findOneAndUpdate(
{
_id: expeditionId,
inviteMountaineers: {
$elemMatch: { userId: mongoose.Types.ObjectId(userId) }
}
},
{ useFindAndModify: false },
{ $set: {
'inviteMountaineers.$.status': status,
'inviteMountaineers.$.paidStatus': paidStatus,
'inviteMountaineers.$.paidAmount': amount,
}
}
).populate({
path: 'inviteMountaineers',
populate: {
path: 'userId',
model: 'User',
},
})
This code returns the expedition object without any update. No update in the database also. Great if someone could help me with this.