Importing to CosmosDB MongoDB API using mongorestore fails with retryable writes error

Viewed 1926

I'm trying to export and import data from an old MongoDB database server to Azure CosmosDB with MongoDB API using mongodump and mongorestore. But i'm having issues with the connection to CosmosDB. I'm using a connection string with the URI flag.

My mongorestore command including connection string is the following:

mongorestore --uri="mongodb://$COSMOS_USERNAME:$COSMOS_PASSWORD@$COSMOS_HOST:$COSMOS_PORT/?maxIdleTimeMS=120000&retrywrites=false&appName=@$DB_NAME@&replicaSet=globaldb&ssl=true" --archive="$ARCHIVE_NAME"

The error message from the command is:

error restoring from archive 'testProdExport.archive': (BadValue) Retryable writes are not supported. Please disable retryable writes by specifying "retrywrites=false" in the connection string or an equivalent driver specific config.

As you can see in the connection string i'm including the retrywrites=false URI parameter, but it looks like CosmosDB doesn't recognize the parameter.

Does anyone have experience with something similar?

//Edit: I've tried and verified that the connection string is working in a mongoose connection as well as in MongoDB Compass.

4 Answers

I found that the various mongotools (mongoimport, mongorestore, etc.) seem to ignore the retrywrites=false or retryWrites=false in the URI, but tacking on the option --writeConcern="{w:0}" allows the command to run successfully on instances that don't support retryable writes

On Windows, didn't have luck with appending on the connectionstring (not necessary if copied from Azure portal)

retryableWrite=false

nor --writeConcern w:0 switch But I ended up trying all previous archives and the magic combination of mongo tools 100.0.0 worked on CosmosDB with MongoServer v3.6.

Attention: Please take care that this can lead to missing data in the collections you restored. Tested it multiple times with different versions of mongorestore. Use the version which is in the mongoserver archive with version 4.0.27. You don't need to provide writeConcern at all in this version. It will also display how many documents are restored instead of 0 in the newer versions.

This affects CosmosDb with API v4.0.

Related