I want to update a sub dictionary in an array.
my array like this
"comments" : [
{
"text" : "hi",
"_id" : ObjectId("56c552dd0a0f08b502a56521"),
"author" : {
"id" : ObjectId("56c54c73f96c51370294f254"),
"photo" : "",
"name" : ""
}
},
{
"text" : "Good",
"_id" : ObjectId("56c5911fc33b446c05a4dabc"),
"author" : {
"id" : ObjectId("56c54be6f96c51370294f123"),
"name" : "xxxx",
"photo":null
}
}
]
I want to update name and photo for this Id author.id:"56c54be6f96c51370294f123".
I wrote the code like this:
Event.find({'comments.author.id':_id},(err,event)=>{
_.each(event,function(eventData){
_.each(eventData.comments,function(commentData){
if(commentData.author.id == _id){
var data={'name':username,'photo':photoUrl};
Event.update({'commentData.author.id':_id},
{"$set":{"eventData.comments.author":data}},(err,commentupdate)=>{
console.log("commentupdate:"+JSON.stringify(commentupdate))
})
}
})
})
})
But I am unable to update the data please give me any suggestions. Thanks