> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/ja/mentenansu/updating-mongodb.md).

# MongoDB の更新

{% hint style="info" %}
Server CE/Server Pro の新しいリリースでは、サポートされる MongoDB バージョンの変更があれば、その [リリースノート](https://docs.overleaf.com/on-premises/release-notes).
{% endhint %}

### MongoDB を更新すべきですか？

次の場合にのみ **のみ** Server CE/Server Pro インスタンスのアップグレードを予定している場合は、MongoDB バージョンの更新を検討してください。

現在（または対象）のバージョンで推奨されているものより新しい MongoDB バージョンを実行している場合は、変更する必要はありません。

{% hint style="warning" %}
MongoDB のバージョンをダウングレードしてはいけません。
{% endhint %}

現在の MongoDB バージョンに関連していると思われる特定の問題が発生した場合は、遠慮なく [問題を報告](https://github.com/overleaf/overleaf/issues) Server CE ユーザーの場合は行うか、Server Pro ユーザーの場合は Overleaf サポートにお問い合わせください。

### MongoDB バージョンの確認

開くと、 `mongo` シェルには現在のバージョンがすぐに表示されるはずです。

Overleaf Toolkit ユーザー：

```bash
bin/docker-compose exec mongo mongod --version
db version v5.0.24
Build Info: {
    "version": "5.0.24",
    "gitVersion": "f034f0c51b3dffef4b8c9452d77ede9888f28f66",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}
```

Docker Compose ユーザー：

```bash
docker compose exec mongo mongod --version
db version v5.0.24
Build Info: {
    "version": "5.0.24",
    "gitVersion": "f034f0c51b3dffef4b8c9452d77ede9888f28f66",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

```

### 更新プロセス

Server CE/Server Pro インスタンスのアップグレード中に MongoDB のバージョンを更新する手順は次のとおりです：

1. アップグレード先の Server CE/Server Pro バージョンを決定します。
2. その特定の Overleaf Server CE/Server Pro リリースで推奨されている MongoDB バージョンを確認します。
3. MongoDB を対象バージョンにアップグレードする手順に従います。
4. Server CE/Server Pro イメージのバージョンをアップグレードし、インスタンスを再起動します。

常にアップグレードすることを推奨します **Server CE/Server Pro** 最新の利用可能なバージョンへ。常にサポートが保証されているためです（Server Pro ユーザーのみ）。

{% hint style="danger" %}
Server CE/Pro のアップグレードを実施する際は、デプロイ済みメジャーバージョンの最新リリースにアップグレードすることをお勧めします **前に** の最新リリースへアップグレードする **次の** メジャーバージョン。デプロイメントが最新バージョンより 2 つ以上のメジャーバージョン遅れている場合は、複数段階のアップグレードを実施する必要があります。

たとえば、3.5.10 を実行している場合は、3.5.13 -> Full Project History の移行を実施 -> 4.2.9 -> 5.5.4 の順にアップグレードする必要があります。

次の場合にのみ **決して** メジャーバージョンをスキップしないでください（3.5.10 -> 5.5.4）。Toolkit を使用しており、最新バージョンより 2 つ以上のメジャーバージョン遅れている場合は、 **しないでください** を使用 `bin/upgrade` スクリプトは使用しないでください。手動で複数段階のアップグレードを実施する必要があります。
{% endhint %}

{% hint style="warning" %}
必ず次のものを取得することが重要です： [整合性のあるバックアップ](/on-premises/ja/mentenansu/data-and-backups.md#performing-a-consistent-backup) **前に** ロールバックが必要になった場合に備え、メジャーバージョンをアップグレードするたびに取得してください。
{% endhint %}

#### バージョンサポート情報

以前のバージョンに戻す場合、この表は以前の Server CE/Server Pro リリースに推奨される MongoDB バージョンを示していますが、次の操作を行う必要があります **決して** MongoDB のバージョンをダウングレードしてください。

<table><thead><tr><th width="175">Server CE/Server Pro</th><th width="139" align="center">MongoDB バージョン</th><th align="center">最小機能互換性バージョン</th><th align="center">Node.js ドライバーでサポートされる最大バージョン</th></tr></thead><tbody><tr><td>2.0.x</td><td align="center">3.4</td><td align="center">-</td><td align="center">-</td></tr><tr><td>2.1.x ～ 2.4.x</td><td align="center">3.6</td><td align="center">-</td><td align="center">-</td></tr><tr><td>>=2.5.0</td><td align="center">4.0</td><td align="center">-</td><td align="center">-</td></tr><tr><td>>=3.1.0</td><td align="center">4.2</td><td align="center">-</td><td align="center">-</td></tr><tr><td>>=3.2.0</td><td align="center">4.4</td><td align="center">-</td><td align="center">-</td></tr><tr><td>>=4.2.0</td><td align="center">5.0</td><td align="center">-</td><td align="center">-</td></tr><tr><td>>=5.1.0</td><td align="center">6.0</td><td align="center">-</td><td align="center">-</td></tr><tr><td>>=5.3.1</td><td align="center">6.0</td><td align="center">5.0</td><td align="center">8.0</td></tr><tr><td>>=5.5.0</td><td align="center">6.0</td><td align="center">6.0</td><td align="center">8.0</td></tr><tr><td>6.0.0</td><td align="center">8.0</td><td align="center">8.0</td><td align="center">8.0</td></tr></tbody></table>

{% hint style="danger" %}
上記の最小機能互換性バージョンは、表示されている Overleaf バージョンでの使用が推奨される対応する MongoDB バージョンに基づいています。より上位のバージョンを使用する場合、MongoDB 独自の最小要件が適用されます。
{% endhint %}

MongoDB で使用するためにサポートされる MongoDB Node.js ドライバーのバージョンを示す互換性表は、 [こちら](https://www.mongodb.com/docs/drivers/node/current/reference/compatibility/).

MongoDB の各バージョンのサポート終了状況は、 [こちら](https://endoflife.date/mongodb).

#### MongoDB のアップグレード

MongoDB では **段階的なアップグレード**が必要です。つまり、たとえば次のバージョンから直接移行することはできません `4.0` から `5.0`へ。まず更新する必要があります `4.2` から `4.4`、その後 `5.0`.

{% hint style="info" %}
MongoDB は安定版に偶数のバージョン番号を使用します。
{% endhint %}

#### **Docker 外で MongoDB を実行している場合の更新手順**

MongoDB をアップグレードする際の mongodb.com の更新手順へのリンクを以下に示します。

* [MongoDB リリースノート - MongoDB のアップグレード元 `4.2` から `4.4`](https://www.mongodb.com/docs/v4.4/release-notes/4.4-upgrade-standalone/)
* [MongoDB リリースノート - MongoDB のアップグレード元 `4.4` から `5.0`](https://www.mongodb.com/docs/v5.0/release-notes/5.0-upgrade-replica-set/)
* [MongoDB リリースノート - MongoDB のアップグレード元 `5.0` から `6.0`](https://www.mongodb.com/docs/v6.0/release-notes/6.0-upgrade-replica-set/)
* [MongoDB リリースノート - MongoDB のアップグレード元 `6.0` から `7.0`](https://www.mongodb.com/docs/manual/release-notes/7.0-upgrade-replica-set/#std-label-7.0-upgrade-replica-set)
* [MongoDB リリースノート - MongoDB のアップグレード元 `7.0` から `8.0`](https://www.mongodb.com/docs/manual/release-notes/8.0-upgrade-replica-set/#std-label-8.0-upgrade-replica-set)

{% hint style="info" %}
次のバージョン向けの手順 `5.0` 以降のバージョンでは、スタンドアロンではなくレプリカセットのインストールを指示しています。Server Pro/CE 4.0.1+ はトランザクションを使用するため、MongoDB をレプリカセットとして実行する必要があります。
{% endhint %}

{% hint style="warning" %}
MongoDB 3.2 から 4.2 のドキュメントは現在、以下から利用できます： <https://www.mongodb.com/docs/legacy/>
{% endhint %}

**基本手順**

ほとんどの場合、更新では実際に mongo のバージョンを更新する前に、互換性フラグを設定する必要があります。手順は次のとおりです：

1. MongoDB リリースノートに記載されているとおりに互換性フラグを設定します（以下の例を参照）。
2. 次に、mongo イメージを更新します：
   1. **Toolkit ユーザー** 更新 `MONGO_VERSION`、例： `MONGO_VERSION=6.0`
   2. **Docker Compose ユーザー** 次のバージョンを更新します： `mongo` イメージタグ、\
      例： `services -> mongo -> image: mongo:6.0`;

**例：MongoDB のアップグレード元 `5.0` から `6.0`**

まず、MongoDB を実行していることを確認します `6.0`:

Overleaf Toolkit ユーザー：

```bash
bin/docker-compose exec mongo mongod --version
# db version v5.0.24
```

Docker Compose ユーザー：

```bash
docker compose exec mongo mongod --version
# db version v5.0.24
```

以下に従って [アップグレード手順](https://docs.mongodb.com/manual/release-notes/3.6-upgrade-standalone/#upgrade-version-path)によると、唯一の要件は `featureCompatibilityVersion` を設定することです `5.0`。MongoDB シェルを開き、指定されたコマンドを実行します：

Overleaf Toolkit ユーザー：

```bash
bin/mongo
# MongoDB shell version v5.0.24
# ...
# overleaf:PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )
# { 
# "ok" : 1,
# ...
# }
overleaf:PRIMARY> exit
# bye
```

{% hint style="info" %}
Docker Compose ユーザーは以下を実行できます `docker compose exec mongo mongosh` シェルを起動し、Toolkit ユーザーと同じコマンドを実行します。
{% endhint %}

Overleaf Toolkit ユーザー：

次に、以下を使用して Server CE/Server Pro と MongoDB のインスタンスを停止します `bin/stop` コマンド、設定 `MONGO_VERSION=6.0` を `config/overleaf.rc`、その後、次を使用して `mongo` サービスを再起動します `bin/up mongo`) を使用して、更新が問題なく完了したことを確認します。

最後に、Server CE/Server Pro イメージのバージョンを対象バージョンに更新し、以下を使用してすべてのサービスを再作成します `bin/up -d` コマンド。

Docker Compose ユーザー：

次に、以下を使用して Server CE/Server Pro と MongoDB のインスタンスを停止します `docker compose stop` コマンド、更新 [`docker-compose.yml`](https://github.com/overleaf/overleaf/blob/4b1babd4ea634ab12c54e9a9aea7db0e8a500941/docker-compose.yml) ファイルで以下を使用します `image: mongo:6.0`、その後、次を使用して `mongo` 以下を使用してサービスを `docker compose up mongo` コマンドで再起動し、更新が問題なく完了したことを確認します。

最後に、Server CE/Server Pro イメージのバージョンを対象バージョンに更新し、以下を使用してすべてのサービスを再作成します `docker compose up` コマンド。

**例：MongoDB のアップグレード元 `6.0` から `7.0` （Toolkit ユーザー）**

まず、MongoDB を実行していることを確認します `6.0` 以下を使用して `mongod --version` 上記のコマンド。

以下に従って [アップグレード手順](https://www.mongodb.com/docs/manual/release-notes/7.0-upgrade-replica-set/#std-label-7.0-upgrade-replica-set)によると、唯一の要件は `featureCompatibilityVersion` を設定することです `6.0`。MongoDB シェルを開き、次のコマンドを実行します `db.adminCommand({ setFeatureCompatibilityVersion: "6.0" })` .

Overleaf Toolkit ユーザー：

```bash
bin/mongo
# ...
# overleaf:PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )
# { 
# "ok" : 1,
# ...
# }
overleaf:PRIMARY> exit
# bye
```

次に、以下を使用して Server CE/Server Pro と MongoDB のインスタンスを停止します `bin/stop` コマンド、設定 `MONGO_VERSION=7.0` を `config/overleaf.rc`、その後、次を使用して `mongo` サービスを再起動します `bin/up mongo`) を使用して、更新が問題なく完了したことを確認します。

最後に、Server CE/Server Pro イメージのバージョンを対象バージョンに更新し、以下を使用してすべてのサービスを再作成します `bin/up -d` コマンド。

**例：MongoDB のアップグレード元 `7.0` から `8.0` （Toolkit ユーザー）**

まず、MongoDB を実行していることを確認します `7.0` 以下を使用して `mongod --version` 上記のコマンド。

以下に従って [アップグレード手順](https://www.mongodb.com/docs/manual/release-notes/8.0-upgrade-replica-set/#std-label-8.0-upgrade-replica-set)によると、唯一の要件は `featureCompatibilityVersion` を設定することです `7.0`。MongoDB シェルを開き、次のコマンドを実行します `db.adminCommand({ setFeatureCompatibilityVersion: "7.0", confirm: true })`。これには追加の `confirm: true` パラメーターが必要になったことに注意してください。

```bash
bin/mongo
# ...
# overleaf:PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )
# { 
# "ok" : 1,
# ...
# }
overleaf:PRIMARY> exit
# bye
```

次に、以下を使用して Server CE/Server Pro と MongoDB のインスタンスを停止します `bin/stop` コマンド、設定 `MONGO_VERSION=8.0` を `config/overleaf.rc`、その後、次を使用して `mongo` サービスを再起動します `bin/up mongo`) を使用して、更新が問題なく完了したことを確認します。

最後に、Server CE/Server Pro イメージのバージョンを対象バージョンに更新し、以下を使用してすべてのサービスを再作成します `bin/up -d` コマンド。

#### docker compose ユーザー向けの同等のコマンド

docker compose ユーザーの場合、同等のコマンドは次のとおりです：

* `docker compose exec mongo mongod --version` mongo のバージョンを表示するには
* `docker compose exec mongo mongosh` 管理コマンド用の mongo シェルを起動するには
* `docker compose stop` サーバーを停止するコマンド
* 次を編集します [`docker-compose.yml`](https://github.com/overleaf/overleaf/blob/4b1babd4ea634ab12c54e9a9aea7db0e8a500941/docker-compose.yml) ファイルで以下を使用します `image: mongo:6.0` mongo のバージョンをアップグレードするには
* `docker compose up mongo` mongo サービスを再起動し、更新が問題なく完了したことを確認するには
* 次を編集します [`docker-compose.yml`](https://github.com/overleaf/overleaf/blob/4b1babd4ea634ab12c54e9a9aea7db0e8a500941/docker-compose.yml) ファイルで以下を使用します `image: sharelatex:VERSION` イメージバージョンをアップグレードするには
* `docker compose up` すべてのサービスを再作成するには。

### カスタムロールの作成

バージョン `5.5.1`では、MongoDB の機能互換性バージョンを検証する起動時チェックを導入しました。MongoDB データベースで認証（例：基本認証）を使用している場合、 `sharelatex` コンテナが起動せず、「*admin に対してコマンドを実行する権限がありません*」という権限エラーが表示される場合があります。

これを解決するには、以下の手順を使用して MongoDB に新しいロールを作成し、データベースへのアクセスに使用するユーザーアカウントに割り当てるか、次を設定します `ALLOW_MONGO_ADMIN_CHECK_FAILURES=true` を設定して、デプロイメントの起動を妨げずにチェックの失敗を許可します。

{% hint style="success" %}
この新しいロールは **のみ** クラスター全体の MongoDB サーバーパラメーターを読み取る権限を付与し、監視目的で再利用できます。
{% endhint %}

{% code overflow="wrap" %}

```bash
# Toolkit ユーザー
$ bin/docker-compose exec -it mongo mongosh -u {{YOUR-ADMIN-USERNAME}} -p

# 以下を使用して "admin" データベースに切り替えます
overleaf [direct: primary] sharelatex> use admin
admin データベースに切り替えました
overleaf [direct: primary] admin> 

# "getParamter" を使用する権限を持つ新しいロールを作成します。以下の関数をシェルにコピー＆ペーストし、Enter キーを押してください

db.createRole(
  {
    role: "clusterParameterReader",
    privileges: [
      {
        resource: { cluster: true },
        actions: ["getParameter"]    
      }
    ],
    roles: [] 
  }
);

# "sharelatex" データベースに戻ります 
use sharelatex
sharelatex データベースに切り替えました
overleaf [direct: primary] sharelatex> 

# 以下の関数をシェルにコピー＆ペーストして Enter キーを押し、新しい "clusterParameterReader" ロールをデータベースユーザーに割り当てます 
db.grantRolesToUser(
  "{{YOUR-DATABASE-USER}}",
  [
    { role: "clusterParameterReader", db: "admin" }
  ]
);

# exit と入力してから Enter キーを押し、MongoDB シェルを終了します
# bin/up -d を実行してデプロイメントスタックを起動します
$ bin/up -d
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/ja/mentenansu/updating-mongodb.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
