def __enter__(self):
        self.db.set_profiling_level(0)
        self.db.system.profile.drop()
        self.db.set_profiling_level(2)
        return self
On every with block we need to drop the profile collection.
dataset/ETHPy150Open MongoEngine/mongoengine/mongoengine/context_managers.py/query_counter.__enter__