Như tài liệu
cho findOneAndUpdate chỉ định, bạn cần bao gồm đối tượng chiếu của mình dưới dạng select thuộc tính của options tham số:
theCollection.findOneAndUpdate(
{ name : 'cherif',
'friends.name':'kevin'
},
{ $set:{
'friends.$.age':25
}
},
{ select: {
friends: {
$elemMatch:
{ age : 25 }
}
}
},
function(err,result){
if (!err) {
console.log(result);
}
});