Home > other >  DocumentDB/MongoDB UpdateOne - Retryable writes are not supported
DocumentDB/MongoDB UpdateOne - Retryable writes are not supported

Time:12-08

I have following bulk_write to upsert each document from my dataset to a collection.

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)

It runs fine running on a local MongoDB server but I am getting following error message when running on AWS DocumentDB. There's a way around which is I delete and insert each record, but want to understand why this happens and use Update instead of 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)}

CodePudding user response:

Amazon DocumentDB does not currently support retryable writes so they need to be disabled with retryWrites=False since they are enabled by default by the driver as explained here: https://docs.aws.amazon.com/documentdb/latest/developerguide/functional-differences.html#functional-differences.retryable-writes

CodePudding user response:

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

Looks like for DocumentDB connection I need to set retryWrites=False, adding this to MongoClient worked :)

  • Related