我有下面的bulk_write来将每个文档从我的数据集更新到一个集合。
data = [] # list of dicts/documents
mongo = MongoClient('some_host')
db = mongo['some_db']
collection = db['some_collection']
operations = [UpdateOne({'_id': d['_id']}, {'$set': d}, upsert=True) for d in data]
result = collection.bulk_write(operations)
它在本地MongoDB服务器上运行良好,但在AWS DocumentDB上运行时收到以下错误消息。有一种方法是我删除和插入每个记录,但要了解为什么会发生这种情况,并使用更新,而不是删除+插入pymongo.errors.OperationFailure: Retryable writes are not supported, full error: {'ok': 0.0, 'code': 301, 'errmsg': 'Retryable writes are not supported', 'operationTime': Timestamp(1638883052, 1)}
3条答案
按热度按时间hvvq6cgz1#
Amazon DocumentDB目前不支持可重试写入,因此需要使用retryWrites=False禁用它们,因为它们在默认情况下由驱动程序启用,如下所述:https://docs.aws.amazon.com/documentdb/latest/developerguide/functional-differences.html#functional-differences.retryable-writes
ifsvaxew2#
根据这个答案:
Mongoose findOneAndUpdate throw "Retryable writes are not supported" error when working with aws Documentdb
retryWrites=False
,将其添加到MongoClient工作:)e4yzc0pl3#
我可以通过在mongoid.yml中的DB配置的选项节中添加
retry_writes: false
来禁用Rails7.0.5和mongoid8.0.3中的可重试写入来解决这个问题