Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure when writing to Cosmos MongoDB Service #1717

Closed
dgomezc opened this issue Feb 12, 2021 · 2 comments
Closed

Failure when writing to Cosmos MongoDB Service #1717

dgomezc opened this issue Feb 12, 2021 · 2 comments
Assignees
Labels
bug Something is broken Generated Code Template code that is generated
Milestone

Comments

@dgomezc
Copy link
Collaborator

dgomezc commented Feb 12, 2021

Describe the bug
When writing to a Cosmos MongoDB service from a generated app we get the following error:
"Retryable writes are not supported. Please disable retryable writes by specifying "retrywrites=false" in the connection string or an equivalent driver specific config."

To Reproduce
Steps to reproduce the behavior:

  1. Launch Web Templates Studio
  2. Select any frontend and backend framework
  3. Add a List page and a Cosmos DB Service with MongoDB
  4. Click create
  5. Accept connection string replacement dialog
  6. Start the app
  7. Try to add something to the list
  8. See error
@dgomezc dgomezc added bug Something is broken Generated Code Template code that is generated labels Feb 12, 2021
@ghost ghost added the needs-triage For new issues that are raised to get reviewed by internal Microsoft employees label Feb 12, 2021
@dgomezc
Copy link
Collaborator Author

dgomezc commented Feb 12, 2021

To solve this, add the property retryWrites = false in your backend framework:

  • Node/Express:
    • Open backend/mongo/mongoConnect.js file.
    • In connect function, add useUnifiedTopology: true and retryWrites: false below useNewUrlParser: true.
function connect() {
  mongoose
    .connect(`${process.env.COSMOSDB_CONNSTR}?ssl=true&replicaSet=globaldb`, {
      auth: {
        user: process.env.COSMOSDB_USER,
        password: process.env.COSMOSDB_PASSWORD
      },
      useNewUrlParser: true,
      useUnifiedTopology: true,
      retryWrites: false
    })
    .then(() => console.log("Connection to CosmosDB successful"))
    .catch(err => console.error(err));
}
  • Flask:
    • Open backend/src/mongo/client.py file.
    • Add retryWrites=false to connection string in MongoClient().
client = MongoClient(connection_str + '?ssl=true&replicaSet=globaldb&retryWrites=false')
  • ASP.NET
    • Open backend/startup.cs file.
    • In InitializeCosmosClientInstance() method add settings.RetryWrites = false; before return new MongoClient(settings);.
private IMongoClient InitializeCosmosClientInstance()
{
   var connectionString = Configuration["COSMOSDB_CONNSTR"];
   var userName = Configuration["COSMOSDB_USER"];
   var dbName = Configuration["COSMOSDB_DB_NAME"];
   var password = Configuration["COSMOSDB_PASSWORD"];
   
   var settings = MongoClientSettings.FromConnectionString(connectionString);
   
   var identity = new MongoInternalIdentity(dbName, userName);
   var evidence = new PasswordEvidence(password);
   settings.Credential = new MongoCredential("SCRAM-SHA-1", identity, evidence);
   
   settings.UseTls = true;
   settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
   settings.RetryWrites = false;
   
   return new MongoClient(settings);
}
  • Moleculer
    • Open backend/mixins/db.mixin.js file.
    • In MongoAdapter constructor, add retryWrites: false below useUnifiedTopology: true.
adapter: new MongoAdapter(
  `${process.env.COSMOSDB_CONNSTR}?ssl=true&replicaSet=globaldb`,
  {
    auth: {
      user: process.env.COSMOSDB_USER,
      password: process.env.COSMOSDB_PASSWORD
    },
    useNewUrlParser: true,
    useUnifiedTopology: true,
retryWrites: false
  }
),

@sibille sibille changed the title Failed when execute an App with Cosmos MongoDB Service Failure when writing to Cosmos MongoDB Service Feb 12, 2021
@dgomezc dgomezc self-assigned this Feb 12, 2021
@dgomezc dgomezc added In Progress Indicates the issue is currently being worked on and removed needs-triage For new issues that are raised to get reviewed by internal Microsoft employees In Progress Indicates the issue is currently being worked on labels Feb 15, 2021
@sibille sibille added this to the 0.5 milestone Feb 18, 2021
@prupipho
Copy link
Contributor

Fixed and tested in version: 0.5.2104801

@prupipho prupipho modified the milestones: 0.5, 0.6 Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken Generated Code Template code that is generated
Projects
None yet
Development

No branches or pull requests

3 participants