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

并行查询各分段

concurrent 选项可启用查询内并行机制。在此模式下, MongoDB Search 会利用更多资源,但会改善每个单独查询的延迟。此功能仅适用于专用搜索节点。

When you run queries with the concurrent option, MongoDB Search doesn't guarantee that each query executes concurrently. For example, when too many concurrent queries are queued, MongoDB Search might fallback to single-threaded execution.

concurrent 通过以下语法实现:

{
"$searchMeta"|"$search": {
"index": "<index name>", // optional, defaults to "default"
"<operator>": {
<operator-specifications>
},
"concurrent": true | false,
...
}
}

The concurrent boolean option allows you to request MongoDB Search to parallelize query execution across segments, which often improves the response time. You can set one of the following values for the concurrent option:

  • true —请求MongoDB Search 以多线程方式运行查询

  • false - 单线程运行查询(默认)

MongoDB Search 允许您按查询控制此行为,仅对繁重且长时间运行的查询启用并发启用,从而最大限度地减少争用并提高整体查询吞吐量。并发执行在大型数据集上尤其有效,因为数据段的数量更多。

MongoDB Search runs a concurrent query on multiple threads, so the query completes faster. But the query consumes more CPU on your Search Nodes while it runs. Enabling the concurrent option for high-volume or short-running queries can saturate the CPU on your Search Nodes and reduce overall query throughput. To limit the impact on CPU, enable the concurrent option only for the heavy and long-running queries that benefit from lower latency.

To measure the CPU cost of an individual query, run the query with explain and review the userTimeMs, systemTimeMs, and maxReportingThreads fields in the resourceUsage document.

To monitor CPU usage across your deployment, view the Atlas cluster metrics and the Review MongoDB Search Metrics. Atlas can also trigger MongoDB Search alerts that measure the amount of CPU that MongoDB Search processes use. If CPU usage approaches the limits of acceptable performance, scale your Search Nodes vertically or horizontally. To learn more, see Tips for Sizing and Scaling Search Nodes.

考虑以下针对示例数据中的 sample_mflix.movies 集合的查询。该查询指示对 title 中包含术语 new york 的电影进行并发搜索。

1db.movies.aggregate([
2 {
3 "$search": {
4 "text": {
5 "path": "title",
6 "query": "new york"
7 },
8 "concurrent": true
9 }
10 }
11])