gpt4 book ai didi

python - 如何处理pymongo.errors.AutoReconnect : connection closed?

转载 作者:太空狗 更新时间:2023-10-29 19:29:27 26 4
gpt4 key购买 nike

我正在编写一个 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}}})

但是,当我运行这段代码时,我遇到了问题:

   raise AutoReconnect(str(e))
pymongo.errors.AutoReconnect: connection closed

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

最佳答案

来自 PyMongo Docs -

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 并重新运行失败的函数..

关于python - 如何处理pymongo.errors.AutoReconnect : connection closed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29781372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com