对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

Install or Uninstall MongoDB Search on Community in a Docker Container

您可以在MongoDB Community Edition中安装搜索进程mongot。搜索进程可作为映像部署在Docker中。mongot进程支持使用您自己的嵌入或自动嵌入进行全文搜索和语义搜索。

注意

要更快地使用用于实验的部署,请参阅以下自管理部署教程:

在部署mongot 之前,您必须完成以下步骤:

  1. 安装Docker和Docker Compose。

  2. If you want MongoDB Vector Search to automatically generate embeddings for text data in your collection, create endpoint service API keys. To learn more, see Automated Embedding.

    重要

    自动嵌入处于预览状态。在预览期间,功能和相应的文档可能随时更改。要学习;了解更多信息,请参阅预览功能。

    If you don't already have the keys, create the endpoint service API keys from the Atlas UI. We recommend that you create two keys, one for generating embeddings at index-time and another for generating embeddings at query-time, from two Atlas projects.

    注意

    用于生成嵌入的提供商终结点取决于您是从Atlas用户界面创建API密钥,还是直接从 Voyage AI创建 API 密钥。

警告

This procedure provides a simple and insecure default configuration that does not enable access control. The steps create a deployment intended for local experimentation only.

Before exposing these containers and using your setup in production, see the following resources to secure your deployment:

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

注意

You must have a minimum of MongoDB 8.2+ to use MongoDB Search with an on-prem deployment. For more information, see MongoDB Search Compatibility.

有关使用Docker安装MongoDB的更多详细信息,请参阅使用Docker安装MongoDB Community

4

mongot 创建密码文件,以连接到 mongod

示例,选择您的操作系统并将 <mongot_password> 替换为您的密码。然后运行以下命令,创建名为 passwordFile 的文件:

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

注意

-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

  • Replace <your_admin_username> with the username you want to specify for your admin user.

  • Replace <your_admin_password> with the password you want to specify for your admin user.

  • Replace </path/to/data/db> with the path to the local directory for the mounted volume.

  • Replace </path/to/mongod.conf> with the path to the configuration file you created above.

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

运行以下命令连接到您在端口 27017 上启动的 mongod实例,将 <your_admin_username><your_admin_password> 替换为您为管理员用户创建的用户名和密码。

docker exec -it mongod mongosh --port 27017
8

mongot must be able to connect to your MongoDB deployment through a user with the searchCoordinator role.

运行以下命令以连接到 admin数据库:

use admin

要创建具有 searchCoordinator角色的用户:

  • Replace <your-mongot-username> with a username for your mongot user.

  • <your-mongot-password> 替换为您在步骤 5 中的 passwordFile 中指定的密码。

  • 运行以下命令:

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

For more information on creating users, see Create a User on Self-Managed Deployments.

9

您可以使用 YAML 配置文件配置 mongot。您必须将在上一步中指定的用户名指定为 syncSource.replicaSet.username。您还必须将上一步中创建的 passwordFile 指定为 syncSource.replicaSet.passwordFile

For more information on mongot configuration options, see mongot Options.

示例,您可以将设置调整为本地配置,如下所示:

# 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

要在 Community 二进制文件中启动 Search,mongot

  • Replace </path/to/data/mongot> with the path to the local directory for the mounted volume to store mongot data.

  • </path/to/mongot.conf> 替换为您在上一步中创建的 mongot 配置文件的路径。

  • </path/to/passwordFile> 替换为您创建的密码文件的路径。

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-community 的容器在 search-community Docker网络上启动容器。

11

To verify, send a request by using a HTTP client or curl to the /health endpoint. For example, send a curl request similar to the following sample request:

curl localhost:8080/health

端点在响应中返回以下内容之一:

  • SERVING, if the mongot process is running

    mongot might not serve queries as it doesn't check the status of the indexes, which must be in Ready state to serve queries.

  • NOT_SERVING, if the mongot process isn't running

For more information, see Verify Your mongot Connection.

To completely remove MongoDB Search and MongoDB Vector Search from a system, remove the container image, the configuration files, and any data or log directories. The following section guides you through the necessary steps.

1

要删除 mongotUser 用户,运行以下命令:

use admin
db.dropUser("mongotUser")

For details, see db.dropUser().

2

要停止 mongot进程,请停止在Docker中运行的容器映像。

3

要删除mongotmongod 配置文件,请使用配置文件的完整路径运行以下命令:

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

To remove the password file, run the following commands using the full path to the password file:

rm /path/to/passwordFile
5

要删除存储 mongot 数据的数据目录,请使用 mongot数据目录的完整路径运行以下命令:

rm /path/to/mongot/data