I want to insert an element in an array by matching the sibling name. suppose-
{
"_id": {
"$oid": "60e544a5e0762b0b2ef6657e"
},
"user0": "a",
"details": [{
"name": "jon",
"things": [{
"name": "car",
"work": "travel"
}, {
"name": "phone",
"work": "network"
}]
},{
"name": "steve",
"things": [{
"what": "car",
"work": "travel"
}, {
"what": "phone",
"work": "network"
}]
}]
}
I want to insert an object in "things" array with where name is "steve" right now I am doing it like this but is doesn't work
collection.updateOne({_id:docs[0]._id}, {$push:{"details.$[]":{things:req.body.data}}});