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

Install or Uninstall mongot in a Docker Container

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

注意

要更快地使用用于实验的部署,请参阅 MongoDB Search 和 MongoDB Vector Search 本地开发快速入门。

重要

mongot 同步 mongod 的数据,并需要 MongoDB 副本集。独立运行的 mongod 部署不支持 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 密钥。

警告

此过程提供一个最小且不安全的默认配置,该配置不启用访问控制。这些步骤创建一个部署,仅用于本地实验。

在曝露这些容器并在生产环境中使用您的设置之前,请参阅以下资源以保护您的部署:

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.3+ 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

<mongot_password> 替换为您的密码,并运行以下命令以在名为 mongot-secrets 的 Docker 托管命名卷中创建名为 passwordFile 的文件。在后续步骤中启动 mongot 时,您参考的是此卷,而不是托管路径。

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"

在 Windows 上,绑定挂载的托管文件不会在 Linux 容器内保留 Unix 权限位。Docker Desktop 的文件共享层会覆盖您在 NTFS 侧设置的权限,而 Windows 没有原生的 chmod 等效项。前面命令中的临时容器在 Linux 侧正确设置了权限。

注意

-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> 替换为上面创建的配置文件的路径。

  • 在 Windows 上,将每行末尾的反斜杠 (\) 替换为 shell 的行继续字符。命令提示符使用关键字符 (^),PowerShell 使用反引号。

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 实例:

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角色的用户:

  • <mongot_username> 替换为 mongot 用户的用户名。

  • <mongot_password> 替换为您在步骤 4 中的 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.scramAuth.username。您还必须将上一步中创建的 passwordFile 指定为 syncSource.replicaSet.scramAuth.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 二进制文件 (mongot) 中启动搜索,请选择您的操作系统并运行命令:

  • </path/to/data/mongot> 替换为已挂载卷的本地目录路径,用于存储 mongot 数据。

  • </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
  • </path/to/data/mongot> 替换为已挂载卷的本地目录路径,用于存储 mongot 数据。

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

  • mongot 配置文件中的 syncSource.replicaSet.scramAuth.passwordFile 设置为 "/secrets/passwordFile" 而不是 "/passwordFile"。该命令将在步骤 4 中创建的 mongot-secrets 卷在容器中挂载到 /secrets

  • 在 PowerShell 中,将每个插入符号 (^) 替换为反引号。该命令使用插入符号 (^) 行继续字符作为命令提示符。

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

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, 如果 mongot 进程正在运行

    mongot 可能无法提供服务查询,因为它不检查索引的状态,而索引必须处于 Ready 状态才能提供服务查询。

  • NOT_SERVING,如果 mongot 进程未运行

有关详细信息,请参阅验证 mongot 连接。

要从系统中完全删除 MongoDB Search 和 MongoDB 向量搜索,请删除容器映像、配置文件以及任何数据或日志目录。以下部分将指导您完成必要步骤。

1

要删除 mongot 用户,请运行以下命令,并将 <mongot_username> 替换为为 mongot 创建的用户名:

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

For details, see 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