【发布时间】: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