ローカルの MongoDB をアップグレードする方法
概要
ローカルに既に存在するデータを維持しつつ、 MongoDB をアップグレードする方法を説明します。
IMPORTANT
バージョンは必ずメジャーバージョン1つ分ずつアップグレードしてください。
TIP
データを維持しなくて良い場合は、bind mount している volumes ディレクトリを削除すれば、データも削除されるため、MongoDB のバージョンアップが可能です。
手順
- メジャーバージョンが1つ上の image を調べる
docker-compose.local.ymlのimageを変更する- コンテナを起動する
- コンテナに入る
featureCompatibilityVersionを変更するコマンドを実行する
例: mongo:4 から mongo:5.0.28 にアップグレードする場合
1. メジャーバージョンが1つ上の image を調べる
公式ドキュメント から、最新の mongo イメージのタグを調べます。
この場合、mongo:5.0.28 が最新のイメージとなります。
2. docker-compose.local.yml の image を変更する
docker-compose.local.yml の image を変更します。
yml
services:
toruca-mongodb:
image: mongo:5.0.283. コンテナを起動する
sh
yarn run dev:docker:up:https4. コンテナに入る
bash
docker exec -it toruca-backend-core-toruca-mongodb-1 sh5. featureCompatibilityVersion を変更するコマンドを実行する
- 更新先のメジャーバージョンに合わせて、
featureCompatibilityVersionを変更します- 今回の場合は、
5.0に変更します
- 今回の場合は、
bash
> mongo
MongoDB shell version v5.0.28
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("870570a6-5282-425e-99c0-d1912037bcba") }
MongoDB server version: 5.0.28
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2024-08-30T11:32:26.489+09:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2024-08-30T11:32:26.489+09:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' in this binary version
---
> use admin
switched to db admin
> db.adminCommand({ setFeatureCompatibilityVersion: "5.0" })
{ "ok" : 1 }
> exit
bye