What is the best way to update the array element inside the array in MongoDB? For example, the data looks like this:
{
"_id" : ObjectId("6201396b866ffbf1b84fb8f9"),
"title" : "ironman",
"comments" : [
{
"text" : "nihao",
"replies" : [
{
"text" : "hi"
},
{
"text" : "bonjour"
},
{
"text" : "push replies!!!"
}
]
},
{
"text" : "what??",
"replies" : [
{
"text" : "the"
},
{
"text" : "hey"
}
]
},
{
"text" : "push comments!!!"
}
]
}
I want to change
"comments.replies.text: 'hi'"
to
"comments.replies.text: 'hello'"
What would be the best way to write a query if you want to update the elements inside replies?
replieswithin thecommentsarray field. You need to tell which array element you want to update, etc. (more details). See Array Update Operators.arrayFiltersoption.