problem description
I want to update a field in the subdocument array, which has been written according to the official document but cannot be updated. Please take a look at it. Thank you!
related codes
Update method:
modle.updateOne({
"fruit.price":12,
_id:1
},{
$set:{
"fruit.$.sum":30
}
})
model instance:
{
_id:1,
fruit:[{
price:12,
sum:23,
date:"2018.7.6",
add:Array
},
{
price:5,
sum:40,
date:"2018.7.6",
add:Array
}]
}
return result:
{ Ok:1, nModified:0, n:0}
Why didn"t the update succeed when I found one? In addition, what should I do if I want to insert a value into the add
field? Thank you!