Doctrine \ ODM \ MongoDB \ Query \ Builder序列化打破了mongo连接

I have an object that has an instance of Doctrine\ODM\MongoDB\Query\Builder . When I serialize my object, unserialize it, and then try to use the Builder, I get the following error:

Fatal error: Uncaught exception 'MongoException' with message 'The MongoCursor object has not been correctly initialized by its constructor'

I assume that this is because PHP looses its connection to the mongo server in the serialization process. How can I fix this?

You can't. The only thing you can do is to remove that object on serialization and create a new one on unserialization. See the serializable interface in PHP.