def __enter__(self):
        self.cls._meta["db_alias"] = self.db_alias
        self.cls._collection = None
        return self.cls
change the db_alias and clear the cached collection
dataset/ETHPy150Open MongoEngine/mongoengine/mongoengine/context_managers.py/switch_db.__enter__