How to Solve NameError: name 'ObjectId' is not defined -- bson

Solution: Import the 'ObjectId' module

To Solve the error, add the following line to the top of your code.

from bson.objectid import ObjectId

 

For more information:
Python bson ObjectId