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

验证 mongot 连接

使用此页面上的教程来验证 mongot 部署是否处于活动状态并连接到 MongoDB Community 部署。

Install MongoDB Community 和 MongoDB Search。有关安装教程,请参阅Install MongoDB Community Edition和步骤。

1

要检查 mongot 实例的状态,请根据安装方法在终端中运行以下命令之一:

2

要检查 mongot 实例的健康状态,请使用 /health 和 /ready 终结点。

要检查 mongot 是否处于活动状态,请针对 /health 终结点 curl:

注意

默认 healthCheck 地址为 localhost:8080。但是,您可以在 mongot 配置文件的 healthCheck.address 选项中定义地址。

curl localhost:8080/health

终结点返回以下响应之一:

  • {"status":"SERVING"}, 如果 mongot 进程正在运行。

  • {"status":"NOT_SERVING"}, 如果 mongot 进程未运行。

要检查 mongot 是否可以查询,请针对 /ready 终结点 curl:

curl localhost:8080/ready

终结点返回以下响应之一:

  • {"status":"SERVING"},如果 mongot 进程已准备好进行查询。

  • {"status":"NOT_SERVING"}, 如果 mongot 进程尚未准备好查询。

3

如果您在 mongot 配置文件中启用了 Prometheus 指标终结点,curl /metrics 终结点以检索进程级别指标:

curl localhost:9946/metrics

注意

默认 metrics 地址为 localhost:9946。要使用其他地址,请在 mongot 配置文件中设置 metrics.address 选项。

要查看搜索索引复制的状态,请过滤 mongot_replication_mongodb_indexManagerState 指标:

curl -s localhost:9946/metrics | grep -E \ "^(# (HELP|TYPE) mongot_replication_mongodb_indexManagerState|mongot_replication_mongodb_indexManagerState)"
4

要验证索引管理是否处于活动状态,请对任何集合运行搜索索引管理方法。

例如,以下命令检查movies集合上是否存在任何搜索索引:

db.movies.getSearchIndexes()

如果操作成功且没有错误,则索引管理可用。

5

运行端到端搜索查询,以确认完整的查询路径可用。

例如,创建带有搜索索引的 test 集合:

db.test.insertMany([ { name: "alpha" }, { name: "beta" }, { name: "alphabet" }]) db.test.createSearchIndex( "verify-index", { mappings: { dynamic: true } })

验证 MongoDB 构建索引:

db.test.getSearchIndexes()

如果命令返回以下响应,则索引可用于查询:

status: 'READY',queryable: true,

然后,运行搜索查询:

db.test.aggregate([ { $search: { index: "verify-index", text: { query: "alpha", path: "name" } } }])

成功查询确认您正确配置了 mongod 和 mongot。

有关疑难排解 mongot 和 mongod 连接,请参阅自管理部署的 MongoDB Search 疑难排解。