Within our MFlix application, users can post comments on movies. Now, different users, or even the same user, may post different comments on a particular given movie. So for example, I can come over here and say, "This movie is great." Which it actually is, it's pretty good. Awesome. So, I can see here that my post has been correctly posted and submitted. In this lesson, we will look into the update mechanism that MongoDB offers so we can implement such a functionality like putting comments into movies. Not only we are going to be looking to adding comments to a particular existing movie, but also how to increment a counter within those movies documents in method add comment to movie, we implement the feature that enables the user to add comments to a given movie. We got the movie and by updating an embedded array called, comments we implement this functionality. Now we are applying here what is a common MongoDB pattern called subsets, where we keep a subset of the data sets. In this case corresponding to comments within the movie's document. Using this subset paradigm, we will be storing the information of a given comment in two different places. You can find more information on why you would want to do this and learn about other schema design patterns in this lecture notes auxiliary content. Within this implementation, we are about to do two different things. First, we update comments field in the movies document and then we add to a collection that contains all comments in the application, the same comments as the one that is now currently added to that comments in that array. In the movies collection, we are using the push operator to push a comment to the comments array field. Now, if we wouldn't be using an update operator, we would be replacing the document sending back and forth the full amount of comments alongside with a full amount of the information that characterizes a movie back and forth. So this operation here, allows us to save a lot of bandwidth by not sending the full amount and making our operations way much smarter and faster. And that's the main reason why we have these update operators. We are also keeping a movie comment cache limits, a set number of movies, a limit to the amount of movies we are keeping within our movie documents. Now we do this for two main reasons. First and most important one is to avoid unbounded rates. If we keep on growing comments without bound therefore an unbounded array, we will certainly reach problems in terms of documents being too large or even completely uneven document sizes across our collection. The second is to optimize the reads from the movie's collection. We don't need all the comments all at once. We just need to fetch the latest ones and that's exactly what we are doing here by specifying not only the limits, but also how we sort them. That way, we only have a first view of the comments of a movie but if we want to get them all we just need to go back to our database look for it on the comments and get the full amount. Smart right? With slice, sort and each which are MongoDB update operated modifiers, combined with the array operator in this case push, it allows us to express conditions on how the update operator handles the field values. In this particular case, we are implementing a cache array by defining a specific set of a slice or a number or limit for our slides. We are defining that our array of comments will be kept to that value. But we are not over with update operators here. We also keep the effective number of comments made on a movie by incrementing $Inc. Operator, a field that keeps track of those same comments. After we're done with the update, the next step would be to just add the incoming comments to our comments collection by inserting one and passing along that same comment document. In terms of update operators there are two kinds. We have array update operators, where we have $addToSet, $push, $pop, $pull, $pullAll and even $ position operator, but you also have field update operators, where you can $set, $unset, $inc, $currentDate, $min, $max, $mul, $rename and $setOnInsert and a bunch of other new operators that will certainly be adding on to this update functionality. The important thing to realize here is that the operators enable us to make changes on existing documents in MongoDB without the need for application side logic. For example, we don't need to keep track of the counter ourselves. We can just ask the database to increment or if we would need to get the mean or the max value or even multiply the value that exists in the document without even reading it, we could just do that by setting an update operator. So basically we leave it to the server, the functionality of updating certain conditions given the state of the document without actually needing to read it. To recap, we've used the update operators to avoid replacing the full extent of documents on every single update. $inc, allows us to keep incrementing the number of comments without even reading the actual number. It leaves it to the database to actually do that work. $push appends the elements to the comments array fields. Using the update operator modifiers, we can set a capped array to avoid unbounded arrays and the usage of the subset pattern, allows us to optimize the access patterns to comments.