[mongoDB]PyMongo Cursor Not Found Error

Python跑一个aggregate脚本,报错:pymongo.errors.CursorNotFound: Cursor not found, cursor id: 35411720832

搜了下原因,猜测应该跟我的网络关系比较大。

网络不顺,导致数据传输时间过长,Cursor长时间无操作。等到再对Cursor进行操作的时候,服务器端已经把连接给关闭了,因此报错。

很多人会建议将查找设为no timeout,很遗憾MongoDB并没有对aggregate函数提供no time out选项. 所以问题无法避免.

参考这里:

Stackoverflow-Is it possible to create an aggregation in Pymongo with no timeout for the cursor?

针对find函数,建议的做法是,对Cursor设置batch_size。如果不行才考虑no time out的设置。

具体参考这里:

Stackoverflow-How to get rid of cursor id error in mongodb?

原文地址:https://www.cnblogs.com/oDoraemon/p/7541759.html