1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to MongoDB in Python

Connected

Exercise

Using bulk_write()

As you saw in the video, you can use a handful of operations in .bulk_write():

  • InsertOne()
  • UpdateOne() / UpdateMany() / ReplaceOne()
  • DeleteOne() / DeleteMany()
  • ReplaceOne()

You're doing some spring cleaning in your movie database where some of these will come in handy!

First, your team wants to flag all highly rated Oscar-winning films as "featured" on the homepage. Second, to reduce clutter, you're instructed to remove all movies released a long time ago.

You'll group both changes into a single .bulk_write() operation to execute them together.

Instructions

100 XP
  • Complete the first operation in operations to update all movies with a rating greater than or equal to 8.0 and that have won an oscar; set a new field "featured" to True for these movies.
  • Complete the second operation in operations to delete all movies with a release year before 1980.
  • Perform the .bulk_write() operation on mov and store the result as res.
  • Print out how many documents were modified and how many documents were deleted.