How To Update Field Of Object In Array With Mongoose
I need to find a room by id and update received field to true where user id equals to xx. The document is here: { '_id' : ObjectId('5e5d0d870fc69641a41a3c65'), 'users' : [
Solution 1:
You need the positional $ operator:
Model.update({_id: ObjectId("5e5d0d870fc69641a41a3c65"), "messages.user": ObjectId("5e57d64d92cc878760086980")}, { $set: { "messages.$.received": true } })
Post a Comment for "How To Update Field Of Object In Array With Mongoose"