And as you can see this code is pretty straight forward.
Pretty much most of the heavy lifting is done by delete comment from movie, so
let's go ahead and now look in that comment in the db.py file.
And as you can see, there's a lot going on here.
And that's mostly to deal with the fact that we're caching
the last ten comments on our movies document.
So I really want us to just focus on just this first line of code,
on this use of delete one.
And we're going to go ahead and
look at our Python notebook to look at how this method works.
And the code that we were just looking at,
the comment was deleted by the comments ID.
But we can actually use any kind of filter that find supports to delete comments.
So in this case here I made a filter here that says what a great movie,
which is the comment that I just made on Titanic.
I'm going to store this inside the filter variable.
And now I can go ahead and run this query, and find this exact comment.
And there you go, you can see that here is the comment I made,
What a great movie, on this is the movie ID for Titanic.
But we already know how to find documents.
But I want to show that using the exact same filter,
we can actually also delete comments.
And so, here's our delete result.
And so now when when we run this command we would expect it to no longer
return this document because it was just deleted, and that's exactly what we see.
Moreover, if we go back to MFlix and
refresh this page, we would expect this comment to go away, but it doesn't.
Why doesn't this comment go away?
And that's because,
this specific comment is actually stored on this movie's document.
We cache the comments on the movie's document so
that we don't have to make an additional call to the comments collection,
when they're just viewing this page.
However, we can scroll to the bottom here, and actually look at all 405 comments and
actually just make a single call to the comments collection.
And in here, my comment doesn't exist.
And that's because we actually deleted my comment
if you look back at the Python notebook off of the comments collection.
And that's how the delete one works.
But now what if we want to delete more than one document at a time.
Well that's exactly what the delete many method is for.
Here, I create a variable that has the Titanic's object ID and
then I go ahead and put that into a filter.
And so this should delete all comments in the comments collection for Titanic.
So there should no longer be any Titanic's comments after I execute this cell.
So now, when I refresh this page here,
we're looking at all comments, we would expect them to all go away.
And they're all gone, I can no longer scroll on this page.
There's no more comments.
But you'll notice that it still says we have 405 comments, and
that's because this number is actually stored on the movie's document.
So, let's go ahead and go back to this view of our ten cache comments.
And let's go ahead and remove these 10 cached comments, and
let's also go ahead and update that number so that we don't see all 405 anymore.
So here, I can go ahead and do that.
Here I go ahead and create a movies variable,
which acts as the movie's database.
And here I'm using the $set operator to turn comments into an empty array,
and reset our number of MFlix comments to 0 with the update one command.
And now when I run this, it looks like it worked.
But let's verify by going to MFlix.
All of our comments are still here, but when we refresh the page you can now see
that there are no more comments, which is exactly what we would expect.