I have a collection of topics with data that looks like this:
{
topicId:"LSCv0mnb" ,
createdBy:"Sam",
posts:[
{
postId: "nNP8UDxL",
createdBy: "Sam"
},
{
postId: "aJ8UxLa",
createdBy: "Bob"
}
]
}
{
topicId:"hlsTOgAX" ,
createdBy:"Victoria",
posts:[
{
postId: "E3cJa0Nm",
createdBy: "Sam"
},
{
postId: "Rt0xQnAy",
createdBy: "Jessica"
}
]
}
What I need is to be able to find all createdBy where name is Sam in all documents and in the array of posts and replace it with [deleted] for example:
{
topicId:"LSCv0mnb" ,
createdBy:"[deleted]",
posts:[
{
postId: "nNP8UDxL",
createdBy: "[deleted]"
},
{
postId: "aJ8UxLa",
createdBy: "Bob"
}
]
}
I'm kind of lost how to do it correctly. Should I be using aggregations for it or what would be the way to do it ? Thanks for your help.