And here I'm converting string representations of dates to date
times using the datetime class.
Finally, this is one of the more interesting bits of this
particular script.
It's something we actually can't yet do in the aggregation framework.
Here, I am changing the data type of runtime.
More specifically, I'm really doing two things.
I'm first running a match on runtime, because if you take a look at
any runtime you'll see that it's this ridiculous string of 1 space min,
6 space min, 190 space min.
It's not an integer, so we can't do range queries.
We can't do any of the types of analysis we'd really like to be able to do because
it's a string, and a string that's in an inconvenient form at that.
So here at the top I've compiled this regular expression that will do a match
and will group the different components of the match in such a way
that I can pull out the integer component for that value.
And then I simply convert it to an int here, and
make sure that runtime gets added to the fields to set.
So that here when I construct the update doc,
that's one of the changes that will be made
as we call update_one in order to make the necessary updates to this document.
Now something I want to point out here is that note that we're not doing anything
with title, nothing with year, nothing with plot,
nothing with any of these fields where we've just got a 1 here.
We're essentially we're just passing the value through.
As long as there is a value other than the empty string, we're doing nothing with it.
That's because to update,
we only need to identify the fields that we want to change in some way,
whether it's setting them to a new value or eliminating them from the document.
Now in this example, we're using just two of the update operators, $set, and $unset.
There are a number of other update operators.
See the lecture notes for this lesson for
a link to the relevant MongoDB documentation.
I can increment values.
I can take the min and max, multiplication, a number of operations
with arrays and a whole host of other types of updates that reflect the variety
of different things we have to do when we're transforming our data from messy and
somewhat ill formatted to data that we can actually use.
So take a look at the docs to see what else is possible in update operations.