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

Connected

Exercise

Schema validation with pydantic

It's your turn now! Use pydantic to enforce a schema in your MongoDB operations, defining a Movie class that you use to create a new movie you're about to insert. If you made a typo when creating the new movie, pydantic should complain!

Instructions

100 XP
  • Do the appropriate imports: from pydantic import BaseModel, and from typing import Optional.
  • Complete the definition of the Movie class so that genre is a list of strings and .
  • Finish the definition of new_movie. It was released in 2012 and has a rating of 8.0.
  • Insert the movie into the movies collection (available as mov).