DocumentDB/MongoDB UpdateOne - 不支持可重试写入

lea*_*fun 8 mongodb pymongo aws-documentdb

我有以下的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)
Run Code Online (Sandbox Code Playgroud)

它在本地 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)}

R2D*_*2D2 9

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