AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

Docker コンテナ内の Community に MongoDB Search をインストールまたはアンインストールする

MongoDB Community Edition では、検索プロセス mongot をインストールできます。検索プロセスは、 Dockerではイメージとして配置で利用できます。mongot プロセスは、独自の埋め込みまたは自動埋め込みを使用した全文検索とセマンティック検索をサポートしています。

注意

実験用の配置でより迅速にオンボードするには、MongoDB Search および MongoDB ベクトル検索 ローカル開発クイック スタートを参照してください。

重要

mongot mongod からデータを同期し、MongoDB レプリカセットが必要です。スタンドアロン配置mongodmongot をサポートしません。

mongot を配置する前に、次の手順を完了します。

  1. DockerとDocker Compose をインストールします。

  2. MongoDB ベクトル検索がコレクション内のテキストデータの埋め込みを自動的に生成する場合は、エンドポイントとなる接続されたデバイス API キーを作成します。詳しくは、「自動埋め込み」を参照してください。

    重要

    自動埋め込みはプレビュー段階です。機能および関連するドキュメントは、プレビュー期間中にいつでも変更される可能性があります。「プレビュー機能」を参照してください。

    キーがまだない場合は、Atlas UI からエンドポイントとなる接続されたデバイス API キーを作成します。MongoDB Atlas の2 つのプロジェクトから、インデックス時に埋め込みを生成するためのキーと、クエリ時に埋め込みを生成するためのキーの 2 つのキーを作成することをお勧めします。

    注意

    埋め込みを生成するためのプロバイダーエンドポイントは、Atlas UIからAPIキーを作成するか、Voyage AIから直接 API キーを作成するかによって異なります。

警告

この手順では、アクセス制御を有効にしない最小限の安全でないデフォルト構成を提供します。この手順では、ローカルでの実験のみを目的とした配置を作成します。

これらのコンテナを公開し、本番環境で設定を使用する前に、次のリソースを参照して配置を保護します。

1

mongot Dockerイメージをプルするには、次のコマンドを実行します。

docker pull mongodb/mongodb-community-search:latest

イメージがDockerディスク上にあることを確認するには、次のコマンドを実行します。

docker image ls mongodb/mongodb-community-search
2

データベースと検索コンテナ間のコンテナ間通信用の Docker ネットワークを作成するには、次のコマンドを実行します。

docker network create search-community
3

MongoDB Dockerイメージをダウンロードするには、次のコマンドを実行します。

docker pull mongodb/mongodb-community-server:latest

注意

オンプレミス配置でMongoDB Search を使用するには、少なくともMongoDB 8.2+ が必要です。詳細については、「MongoDB Search の互換性」を参照してください。

Dockerを使用してMongoDBをインストールする方法の詳細については、 Dockerを使用してMongoDB Community をインストール を参照してください。

4

Create a password file for mongot to connect to mongod. Select your operating system and run the command:

Replace <mongot_password> with your password and run the following command to create a file called passwordFile in your current directory:

echo -n "<mongot_password>" > passwordFile
chmod 400 passwordFile

Replace <mongot_password> with your password and run the following command to create a file called passwordFile inside a Docker-managed named volume called mongot-secrets. You reference this volume instead of a host path when you start mongot in a later step.

docker volume create mongot-secrets
docker run --rm -v mongot-secrets:/secrets busybox sh -c "echo -n '<mongot_password>' > /secrets/passwordFile && chmod 400 /secrets/passwordFile"

On Windows, a bind-mounted host file does not preserve Unix permission bits inside a Linux container. Docker Desktop's file-sharing layer overrides the permissions that you set on the NTFS side, and Windows has no native chmod equivalent. The throwaway container in the preceding command sets the permissions correctly on the Linux side.

注意

-n フラグは末尾の改行を防止します。

5

構成ファイルを作成するには、次のコードを mongod.conf または希望する場所に保存します。

# MongoDB Configuration File
# Network configuration
net:
port: 27017
bindIpAll: true # Equivalent to --bind_ip_all
# Replica set configuration
replication:
replSetName: rs0
# Search configuration parameters
setParameter:
# Server parameters to advise mongod of mongot availability for search index management and querying
searchIndexManagementHostAndPort: mongot-community.search-community:27028
mongotHost: mongot-community.search-community:27028
skipAuthenticationToSearchIndexManagementServer: false
useGrpcForSearch: true
searchTLSMode: disabled
6

mongod を起動するには次の手順に従います。

  • </path/to/data/db> をマウントされたボリュームのローカル ディレクトリへのパスに置き換えます。

  • </path/to/mongod.conf> を、上記で作成した構成ファイルへのパスに置き換えます。

  • On Windows, replace the backslash (\) at the end of each line with the line continuation character for your shell. Command Prompt uses a caret (^), and PowerShell uses a backtick.

docker run --rm \
--name mongod \
-v </path/to/mongod.conf>:/etc/mongod.conf:ro \
-v </path/to/data/db>:/data/db \
-p 27017:27017 \
--network search-community \
mongodb/mongodb-community-server:latest \
--config /etc/mongod.conf \
--replSetMember=mongod.search-community:27017
7

Run the following command to connect to the mongod instance you started on port 27017:

docker exec -it mongod mongosh --port 27017
8

mongot searchCoordinator ロールを持つユーザーを介して MongoDB 配置に接続できる必要があります。

次のコマンドを実行して、adminデータベースに接続します。

use admin

searchCoordinator ロールを持つユーザーを作成するには:

  • <mongot_username>mongot ユーザーのユーザー名に置き換えます。

  • <mongot_password> を、ステップ 4 の passwordFile で指定したパスワードに置き換えます。

  • 次のコマンドを実行します:

db.createUser(
{
user: "<mongot_username>",
pwd: "<mongot_password>",
roles: [ "searchCoordinator" ]
}
)

ユーザーの作成の詳細については、「自己管理型配置でユーザーを作成する」を参照してください。

9

YAML構成ファイルを使用して mongot を構成できます。前の手順で指定したユーザー名をsyncSource.replicaSet.scramAuth.username として指定する必要があります。また、前の手順で作成した passwordFilesyncSource.replicaSet.scramAuth.passwordFile として指定する必要があります。

mongot 構成オプションの詳細については、mongot オプションを参照してください。

例では、以下に示すように 設定をローカル構成に合わせて調整できます。

# mongot.conf
syncSource:
replicaSet:
hostAndPort: "mongod.search-community:27017"
scramAuth:
username: "mongotUser"
passwordFile: "/passwordFile"
authSource: "admin"
tls:
enabled: false
replicationReader:
readPreference: "secondaryPreferred"
storage:
dataPath: "/data/mongot"
server:
grpc:
address: "mongot-community.search-community:27028"
tls:
mode: "disabled"
metrics:
enabled: true
address: "mongot-community.search-community:9946"
healthCheck:
address: "mongot-community.search-community:8080"
logging:
verbosity: INFO

ファイルをmongot.config またはご希望のファイルロケーションに保存します。

どちらのコンテナも同じ search-community Dockerネットワークで動作します。

10

To start the Search in Community binary (mongot), select your operating system and run the command:

  • mongot データを保存するには、</path/to/data/mongot> をマウントされたボリュームのローカル ディレクトリへのパスに置き換えます。

  • </path/to/mongot.conf> を、前のステップで作成した mongot構成ファイルへのパスに置き換えます。

  • Replace </path/to/passwordFile> with the path to the password file that you created.

docker run --rm \
--name mongot-community \
-v </path/to/data/mongot>:/data/mongot \
-v </path/to/mongot.conf>:/mongot-community/config.default.yml \
-v </path/to/passwordFile>:/passwordFile:ro \
--network search-community \
-p 8080:8080 \
-p 9946:9946 \
mongodb/mongodb-community-search:latest
  • mongot データを保存するには、</path/to/data/mongot> をマウントされたボリュームのローカル ディレクトリへのパスに置き換えます。

  • </path/to/mongot.conf> を、前のステップで作成した mongot構成ファイルへのパスに置き換えます。

  • Set syncSource.replicaSet.scramAuth.passwordFile in your mongot configuration file to "/secrets/passwordFile" instead of "/passwordFile". The command mounts the mongot-secrets volume that you created in step 4 at /secrets in the container.

  • In PowerShell, replace each caret (^) with a backtick. The command uses the caret (^) line continuation character for Command Prompt.

docker run --rm ^
--name mongot-community ^
-v </path/to/data/mongot>:/data/mongot ^
-v </path/to/mongot.conf>:/mongot-community/config.default.yml ^
-v mongot-secrets:/secrets:ro ^
--network search-community ^
-p 8080:8080 ^
-p 9946:9946 ^
mongodb/mongodb-community-search:latest

このコマンド:

  • ボリュームをマウントします。

  • ローカル ボリュームから構成ファイルをマウントします。

  • ポート範囲を指定します。

  • メトリクス ポートを公開します。

  • mongot-community という名前のコンテナを使用して search-community Dockerネットワーク上のコンテナを起動します。

11

確認するには、HTTP クライアントまたは curl を使用して /health エンドポイントとなる接続されたデバイスにリクエストを送信します。例えば、次のサンプル リクエストと同様の curl リクエストを送信します。

curl localhost:8080/health

エンドポイントは、応答として次のいずれかを返します。

  • SERVING, mongot プロセスが実行中の場合

    mongot インデックスのステータスをチェックしないため、クエリを処理できない可能性があります。クエリを処理するには、インデックスが Ready 状態である必要があります。

  • NOT_SERVING, mongot プロセスが実行されていない場合

詳細については、「mongot 接続の確認」を参照してください。

MongoDB Search と MongoDB ベクトル検索をシステムから完全に除去するには、コンテナイメージ、構成ファイル、およびデータまたはログディレクトリを削除します。次のセクションで必要な手順をご案内します。

1

mongotユーザーを削除するには、<mongot_username>mongotのために作成したユーザー名に置き換えて、次のコマンドを実行します。

use admin
db.dropUser("<mongot_username>")

詳細については、db.dropUser() を参照してください。

2

mongot プロセスを停止するには、 Dockerで実行中のコンテナイメージを停止します。

3

mongotmongod 構成ファイルを削除するには、構成ファイルへのフルパスを使用して次のコマンドを実行します。

rm /path/to/config.default.yml
rm /path/to/mongod.conf
4

パスワード ファイルを削除するには、パスワード ファイルへのフルパスを使用して次のコマンドを実行します。

rm /path/to/passwordFile
5

mongot データを保存しているデータディレクトリを削除するには、mongotデータディレクトリへのフルパスを使用して次のコマンドを実行します。

rm /path/to/mongot/data