【问题标题】:DocumentDB/MongoDB UpdateOne - Retryable writes are not supportedDocumentDB/MongoDB UpdateOne - 不支持可重试写入
【发布时间】:2022-01-12 13:46:47
【问题描述】:

我有关注 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 上运行时出现以下错误消息。有一种方法是我删除并插入每条记录,但想了解为什么会发生这种情况并使用 Update 而不是 Delete+Insert

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)}

【问题讨论】:

    标签: mongodb pymongo aws-documentdb


    【解决方案1】:

    Amazon DocumentDB 目前不支持可重试写入,因此需要使用 retryWrites=False 禁用它们,因为驱动程序默认启用它们,如下所述: https://docs.aws.amazon.com/documentdb/latest/developerguide/functional-differences.html#functional-differences.retryable-writes

    【讨论】:

      【解决方案2】:

      根据这个答案:

      Mongoose findOneAndUpdate throw "Retryable writes are not supported" error when working with aws Documentdb

      retryWrites=False,将此添加到 MongoClient 工作:)

      【讨论】:

        猜你喜欢
        • 2021-02-06
        • 1970-01-01
        • 2017-05-23
        • 1970-01-01
        • 1970-01-01
        • 2021-09-12
        • 1970-01-01
        • 1970-01-01
        • 2018-03-08
        相关资源
        最近更新 更多