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

前端 未结 4 614
逝去的感伤
逝去的感伤 2021-01-03 22:05

I am using \"mongoose\": \"^5.7.1\" in my Node.js project. I am making an api which involves updating in two documents. So, I am using the transactions like fol

相关标签:
4条回答
  • 2021-01-03 22:26

    As suggested in accepted answer, you need to have your local server to be run as a replica set to be able to perform transactions, as opposed to standalone server.

    However, in addition to the proposed solution, you can easily convert your Standalone local db to a Replica Set without using any third-party tool, by following instructions in MongoDB documentation, summarized as follows:

    1. Stop your standalone mongod instance, and restart it with the replSet argument.
    mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0 --bind_ip localhost
    
    1. Connect to your instance with a mongo shell, and initiate the new Replica Set.
    rs.initiate()
    

    Now you should have a Replica Set instead of a Standalone mongodb server, where you can perform transactions on your local environment to update multiple documents at once!

    Do not forget to include the replSet argument every time you want to start the server, otherwise it will be started as Standalone. I simply use the same command as in step 1 to run it again.


    Alternatively, you can deploy a new Replica Set from scratch for testing environment following these other instructions in MongoDB documentation.

    0 讨论(0)
  • 2021-01-03 22:27

    Please Edit App/Config/database file Add 'retryWrites'=>false in Mongodb Connection String

    write Mongo db connection

    'mongodb' => [
                'driver'   => 'mongodb',
                'host'     => env('MONGO_DB_HOST', 'lo*****'),
                'port'     => *****,
                'database' => env('MONGO_DB_DATABASE'),
                'username' => env('MONGO_DB_USERNAME'),
                'password' => env('MONGO_DB_PASSWORD'),
                'options'  => [
                    'database'=> env('MONGO_DB_DATABASE'),
                    'retryWrites'=>false
                ]
            ],
    

    Save And Run

    0 讨论(0)
  • 2021-01-03 22:28

    Transactions are undoubtedly the most exciting new feature in MongoDB 4.0. But unfortunately, most tools for installing and running MongoDB start a standalone server as opposed to a replica set. If you try to start a session on a standalone server, you'll get this error.

    This issue can be resolved by using replica-sets on your local environment.

    I have used run-rs for this purpose.

    0 讨论(0)
  • 2021-01-03 22:31

    Please try adding &retryWrites=false to your connection string

    --

    I actually got the errors mentioned in the OP when connecting to our remote db server, whereas it was working locally. I contacted our mongo hosted support before trying the suggestion that is in the error.

    --

    This is what our hosted mongo site (mLab) said :

    It's likely your app's driver was updated to a more recent version which is attempting to use a WiredTiger-only feature. As the error mentions, you'll need to add &retryWrites=false to your connection string.

    https://docs.mlab.com/faq/#why-am-i-getting-the-transaction-numbers-are-only-allowed-on-storage-engines-that-support-document-level-locking-error

    0 讨论(0)
提交回复
热议问题