How to fix pymongo.errors.InvalidOperation: cannot use cursor after close in Python | DevErrors