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

retryWrites false flag in mogoDb not working #22307

Open
1 task done
tungns0695 opened this issue Mar 8, 2025 · 8 comments
Open
1 task done

retryWrites false flag in mogoDb not working #22307

tungns0695 opened this issue Mar 8, 2025 · 8 comments

Comments

@tungns0695
Copy link

tungns0695 commented Mar 8, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Description

I'm using Volo.Abp.MongoDB version 9.1.0.
Configuration string mongodb://localhost:27017/DbName?retryWrites=false
When i insert record to MongoDb it allways throw error "This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string."

Reproduction Steps

Install mongoDb and use Volo.Abp.MongoDB
Configuration string set to mongodb://localhost:27017/DbName?retryWrites=false

Expected behavior

Should be able to save data.

Actual behavior

Throw error This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.

Regression?

No response

Known Workarounds

Disable UnitOfWork or override InitializeDatabase and not pass SessionHandle to base method

Version

9.1.0

User Interface

Common (Default)

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

@tungns0695 tungns0695 added the bug label Mar 8, 2025
@tungns0695
Copy link
Author

after a bit of testing. The issue cause by dbContext.SessionHandle. If SessionHandle is not null it will throw above error when save the entity. After exception once it will be able to save the data if send request again. SessionHandle will be null in that case

@maliming
Copy link
Member

Thanks @tungns0695

I will check this.

@maliming maliming self-assigned this Mar 10, 2025
@maliming
Copy link
Member

maliming commented Mar 10, 2025

hi @tungns0695

Does your MongoDB database support transactions?

Is it Replica Set or Sharded Cluster

mongodb://localhost:27017/DbName?retryWrites=false

@tungns0695
Copy link
Author

It's a single instance local mongodb server

@tungns0695
Copy link
Author

To put more context. In my service there's two repos . One for EF and one for mongo. The idea is we save data to EF first then save to mongo as snapshot. For mongo we don't require trasction for it at the moment.

@maliming
Copy link
Member

hi

A docker-compose.yml to create mongo with replSet in a single node.

version: "3.8"

services:
  mongo:
    image: mongo:8.0
    command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
    ports:
      - 27017:27017
    healthcheck:
      test: echo "try { rs.status() } catch (err) { rs.initiate({_id:'rs0',members:[{_id:0,host:'127.0.0.1:27017'}]}) }" | mongosh --port 27017 --quiet
      interval: 5s
      timeout: 30s
      start_period: 0s
      start_interval: 1s
      retries: 30

@maliming maliming removed the bug label Mar 10, 2025
@tungns0695
Copy link
Author

tungns0695 commented Mar 10, 2025

can we update document for mongo a bit so it's clear we should config mongo with replSet even using single instance? Due to the error message only let we know that we should set the retryWrites flag to false and i cannot find any document related to this from ABP. Also it's quite strange when first request we just startup the service it will crash but subsequence request work fine without any issue.

@maliming
Copy link
Member

ok, I will add a article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants