I would like to update a subdocument that was fetched using $elemMatch. I\'ve found some posts online but so far I am not able to get it to work. This is what I have:
<You can do this all with a single update
call on the model instead of fetching it first with findOne
:
User.update(
{'addresses._id': address_id},
{$set: {'addresses.$.street': 'Blah'}},
function(err, count) { ... });
This uses the positional $ operator in the $set
to target just the addresses
element that was matched in the query.