I have the following structure in my MongoDb where I have a topic object inside of a topics array. Within the topic object, I have a messages array. What I am trying to do is find every matching record (in this case, 'John Doe') in the collection (let's call it Records), and update the username property. How can I do this?
topics: [
{
topicname : 'Medical Records',
prop: propdata,
messages: [
{
username: 'John Doe',
message: 'Hello'
}
]
}
]
This is what i've tried...
collection.updateOne({'topics.messages.username' : 'John Doe'}, {
'$set':
{
'topics.messages.username' : 'Johnathan Doe'
},
But this does not work. How can I update every property that matches 'John Doe' in my collection?