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

Connected

Exercise

Updating multiple documents

Sometimes, multiple documents need the same update: when correcting an error or tagging records that meet certain conditions, for example. That's where .update_many() comes in.

In this exercise, you'll use it to tag Oscar-winning movies that also have a rating above 7.0 as favorites.

Instructions

100 XP
  • Define query_filter so it matches all movies where "won_oscar" is equal to True, and "rating" is greater than 7.0.
  • Define update to $set a new field "is_favorite" to True.
  • Perform the update for all documents that match query_filter.
  • Print out how many documents were affected by this update.