SuperAPI AI 工具集

mongodb-query-optimizer

数据与分析

查看项目

更新于 10-16 03:47

技能介绍

用途:该技能用于 MongoDB 查询优化与索引建议,仅在用户明确要求优化或性能帮助时启用,例如询问某查询为何慢、如何加速、集群慢查询如何优化。常规查询编写不触发。

主要能力:结合 MongoDB MCP 工具与 Atlas Performance Advisor 收集信息并给出建议。数据库工具包括 collection-indexes(查看集合现有索引)、explain(支持 queryPlanner、executionStats 等 verbosity)、find(取样例文档推断结构)。Atlas 工具包括 atlas-list-projects 与 atlas-get-performance-advisor,后者可获取 slowQueryLogs、suggestedIndexes、dropIndexSuggestions、schemaSuggestions。

使用方式:针对具体查询,典型流程为 collection-indexes → explain → find,再调用 atlas-get-performance-advisor;针对整体性能,直接调用 Performance Advisor 获取慢查询日志与建议。诊断前需加载 references/core-indexing-principles.md 与 references/antipattern-examples.md,聚合管道或更新类查询按需加载对应参考文件。

适用场景:单条查询的索引与执行计划分析、集群慢查询排查、索引增删建议、聚合与更新查询优化。

限制:通用性能分析需要配置带 API 凭据的 Atlas MCP Server,否则应提示用户配置或改为询问具体查询;未配置 MongoDB MCP 时仍可依据最佳实践给出建议。建议应简短、说明理由,避免绝对化表述;集合索引一般不超过 20 个;仅在 Atlas Performance Advisor 建议时才建议删除索引;未经用户批准不得直接通过 MCP 创建索引。不得请求或提交连接字符串、密钥。该技能可在 GitHub Copilot、Claude Code、Codex 间移植,Codex 需同步到 $CODEX_HOME/skills/mongodb-query-optimizer 并重启。