LoginSignup
0
0

More than 3 years have passed since last update.

mLabを使用してMongoDBの書き込み時に"MongoError: This MongoDB deployment does not support retryable writes"のエラー

Posted at

概要

MongoDBをクラウド上で提供しているmLab MongoDBというサービスがあるのですが、データの書き込みを行った時に、MongoError: This MongoDB deployment does not support retryable writesのエラーが発生したので、対応方法をメモします。

原因

このStack Overflowの記事によると、mLabではMongoDBの接続設定retryWritesオプションが使用できないので、falseにする必要があるとのこと。
retryWritesオプションは書き込みのエラー発生時に、DB側で自動的にretryしてくれる機能で、公式のマニュアルによると、MongoDB4.2のドライバーだとデフォルトでtrueになるみたいです。

接続時の設定

以下はRailsのMongoidを使用した際の、retryWritesオプションをfalseにする設定です。なお、設定ファイルmongoid.ymlの詳細については、mongoid-configurationを参照ください。

mongoid.yml
production:
  clients:
    default:
      database: heroku_test
      hosts:
        - test111111.mlab.com:51180
      options:
        user: "test_user"
        password: "test_password"
        retry_writes: false
  options:
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0