Search code examples
mongodbazure-cosmosdb-mongoapimongorestore

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


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.


Solution

  • You can try a version of mongorestore that shipped with MongoDB 3.4. This may not be able to read recent dumps though.

    The ismaster output you provided includes:

    logicalSessionTimeoutMinutes: 30

    This advertises session support but https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb-feature-support-36 says cosmosdb does not support sessions.

    CosmosDB is advertising support for a feature it does not implement, the tooling then (correctly) attempts to use it. This is a bug in cosmosdb.