我有以下 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)}
uj5u.com熱心網友回復:
Amazon DocumentDB 目前不支持可重試寫入,因此需要使用 retryWrites=False 禁用它們,因為它們默認由驅動程式啟用,如下所述:https ://docs.aws.amazon.com/documentdb/latest/developerguide/functional -differences.html#functional-differences.retryable-writes
uj5u.com熱心網友回復:
Mongoose findOneAndUpdate 在使用 aws Documentdb 時拋出“不支持可重試寫入”錯誤
看起來對于 DocumentDB 連接,我需要設定 retryWrites=False,將此添加到 MongoClient 作業:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/377426.html
上一篇:為什么“_db”變數顯示未定義?
