(Newbie) How to update "cast" name in mflix movie example

Hey Guys,

I’ve only been working with Relational Databases for many years, so it’s a little hard for me to imagine how I would go about doing this properly:

In the mflix movie example data, we will find the cast of the movie with Names as an Array.
So many movies may have the same name (but maybe its not the same guy). But what do i do when one of these people gets married?

So: How do i rename the Name of the people?

In relation-databases there would be a “cast”-Table and a “cast-movie”-Table.
And i will just update the cast-Table Name and the new Name is in all movies.

What is the exact Workflow here in Mongo?

I am sure this question has been asked several times here, but unfortunately i have not found it.


Hey @Patrick_Peters,

Welcome to the MongoDB Community Forums! :leaves:

So you want to do an update to a name that appears across multiple movies or only for some movies since names can be the same for two different people as you mentioned?

As per what you described, you can use update with aggregation pipeline operators. For example, the syntax to update a cast member’s name using $set:

{ title : "<movie name>" , cast:"<Actor's Name>" },
{ $set:{ "field.$" : "<New Name>"}

Similarly, you can use other aggregation operators attached in the documentation based on different use cases. Also note that in the update example above, the update will only be performed on a single document. You can use bulk operation if you want to change all documents containing the name to be changed.

Additionally, since you are a beginner in MongoDB, I would highly recommend you check out our University Courses to help you get started in MongoDB and make you feel more familiar with the concepts. :smile:
Introduction to MongoDB
MongoDB for SQL Pros

Please let us know if there are any doubts about this. Feel free to reach out for anything else as well.


1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.