如何处理pymongo.errors.AutoReconnect:连接关闭?

2024-09-24 02:15:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个python代码来更新集合中的每个文档。我的代码是:

for r, d_50 in enumerate(grid50.find().batch_size(500)):
    self_grid = grid50.find({'_id':d_50['_id']})
    .....
    .....
    (processing process)
    grid50.update({'_id':d_50['_id']},{'$set':{u'big_cell8':{"POI":venue_count, "cell_ids":cell_ids}}})

但是,当我运行此代码时,遇到了一个问题:

^{pr2}$

有人知道如何处理这个问题吗?我应该在代码中添加一些东西来处理这个问题吗?在


Tags: 代码in文档selfididsforsize
1条回答
网友
1楼 · 发布于 2024-09-24 02:15:33

从PyMongoDocs-

exception pymongo.errors.AutoReconnect(message='', errors=None)

Raised when a connection to the database is lost and an attempt to auto-reconnect will be made.

In order to auto-reconnect you must handle this exception, recognizing that the operation which caused it has not necessarily succeeded. Future operations will attempt to open a new connection to the database (and will continue to raise this exception until the first successful connection is made).

基本上,您必须处理这个异常,以便应用程序重新连接到mongo并重新运行失败的函数。。在

相关问题 更多 >