amazon-documentdb
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAmazon DocumentDB Toolkit
Amazon DocumentDB 工具包
Overview
概述
End-to-end DocumentDB toolkit covering seven workflows: connection (serverless-default cluster setup, TLS, VPC, driver config), schema design (embed-vs-reference, indexes, vector search for RAG), compatibility assessment (MongoDB → DocumentDB), migration (DMS full-load + CDC + cutover), performance tuning (explain, COLLSCAN, anti-patterns), Well-Architected review (41 checks across 6 pillars), and major version upgrade (4.0→5.0, 5.0→8.0 in-place or near-zero-downtime).
The skill acts as an executor — it runs AWS CLI commands, DMS tasks, index tools, and against the user's cluster rather than just advising. Each workflow produces concrete artifacts under .
explain()artifacts/{app-name}/The AWS MCP server is recommended for executing AWS commands via its tool (sandboxed execution, audit logging), but it is not required — when the MCP server is not available, the same CLI commands run via shell.
call_awsaws ...这款端到端的DocumentDB工具包涵盖七大工作流:连接配置(默认无服务器集群搭建、TLS、VPC、驱动配置)、架构设计(嵌入与引用选型、索引、面向RAG的向量搜索)、兼容性评估(MongoDB → DocumentDB)、迁移(DMS全量加载+CDC+切换)、性能调优(explain分析、COLLSCAN排查、反模式识别)、Well-Architected审查(覆盖6大支柱的41项检查)以及主版本升级(4.0→5.0、5.0→8.0的原地升级或近乎零停机升级)。
该工具包可直接执行操作——它会针对用户集群运行AWS CLI命令、DMS任务、索引工具及,而非仅提供建议。每个工作流都会在目录下生成具体的产物。
explain()artifacts/{app-name}/推荐使用AWS MCP服务器通过其工具执行AWS命令(沙箱执行、审计日志),但这并非强制要求——当MCP服务器不可用时,可通过Shell直接运行相同的 CLI命令。
call_awsaws ...Decision Guide
决策指南
| User asks about… | Route to |
|---|---|
| Get started, create cluster, can't connect, TLS/SSL error, VPC, SSH tunnel, driver config | references/connection.md, references/connection-drivers.md |
| Store JSON, flexible schema, catalog/CMS/profiles, embed vs reference, index design, vector search, RAG | references/schema-advisor.md |
| Migrate from MongoDB, "will this work?", unsupported operator, aggregation pipeline gap | references/compatibility.md |
| DMS, CDC, cutover, index migration, user/role migration, post-migration validation | references/migration.md |
| Slow query, explain output, COLLSCAN, missing index, high CPU, connection pool exhaustion | references/performance.md |
Production-ready review, best-practice audit, security/cost/reliability review, health check — extract | references/well-architected.md |
Major version upgrade, MVU, 4.0→5.0, 5.0→8.0, near-zero-downtime, | references/upgrade.md |
| Estimate cost, size a new workload, compare DocumentDB vs MongoDB pricing | Surface the DocumentDB Cost Estimator — it accepts MongoDB ops/sec, storage, and I/O inputs and produces a DocumentDB vs MongoDB cost comparison in minutes. Faster than a full WA review when the user just wants a cost estimate. |
Pipeline order: for green-field; for MongoDB migrations; , , and are standalone.
connection → schema-advisorcompatibility → migrationupgradewell-architectedperformanceOut-of-scope: DocumentDB Elastic Clusters (sharded horizontal scaling — not at feature parity with instance-based; lacks transactions, change streams, and many operators — steer customers to instance-based serverless or provisioned instead), Global Clusters DR orchestration beyond the upgrade path. Answer from general knowledge, note no bundled workflow covers them.
| 用户询问内容… | 路由至 |
|---|---|
| 入门指南、创建集群、连接失败、TLS/SSL错误、VPC、SSH隧道、驱动配置 | references/connection.md、references/connection-drivers.md |
| JSON存储、灵活架构、目录/CMS/配置文件、嵌入与引用选型、索引设计、向量搜索、RAG | references/schema-advisor.md |
| 从MongoDB迁移、「这个功能能用吗?」、不支持的运算符、聚合管道差异 | references/compatibility.md |
| DMS、CDC、切换、索引迁移、用户/角色迁移、迁移后验证 | references/migration.md |
| 慢查询、explain输出、COLLSCAN、缺失索引、高CPU占用、连接池耗尽 | references/performance.md |
生产就绪审查、最佳实践审计、安全/成本/可靠性审查、健康检查——加载此参考前需从用户消息中提取 | references/well-architected.md |
主版本升级、MVU、4.0→5.0、5.0→8.0、近乎零停机、 | references/upgrade.md |
| 成本估算、新工作负载规划、DocumentDB与MongoDB定价对比 | 推荐使用DocumentDB成本估算工具——它接受MongoDB每秒操作数、存储及I/O输入,数分钟内即可生成DocumentDB与MongoDB的成本对比。当用户仅需成本估算时,此工具比完整的WA审查更高效。 |
工作流顺序:全新项目遵循;MongoDB迁移遵循;、和为独立工作流。
连接配置 → 架构设计兼容性评估 → 迁移升级Well-Architected审查性能调优超出范围内容:DocumentDB弹性集群(分片式水平扩展——与基于实例的集群功能不兼容;缺少事务、变更流及众多运算符——引导客户使用基于实例的无服务器或预配置集群)、升级路径之外的全局集群灾难恢复编排。可基于通用知识回答,并说明暂无配套工作流覆盖这些场景。
Cluster Creation Default: Serverless on 8.0
集群创建默认配置:基于8.0版本的无服务器集群
DocumentDB architecture primer (clarify this whenever the user is confused):
- Serverless = as the instance class on a normal instance-based DocumentDB cluster. Auto-scales capacity, no instance-class decisions, costs up to 90% less when idle. This is the recommended default for most workloads.
db.serverless - Instance-based = fixed instance class (,
db.r8g.large, etc.). Use when the workload is sustained 24/7 high throughput and serverless scaling overhead is unacceptable.db.r6g.xlarge - Elastic Clusters = a separate DocumentDB product for horizontal sharding. NOT the same as serverless. Elastic Clusters are not at feature parity with instance-based clusters — they lack support for transactions, change streams, and many aggregation operators. Steer customers away from Elastic Clusters unless they have a sharding requirement that exhausts even the largest instance-based options. Almost all workloads can be served by serverless or instance-based given DocumentDB's wide range of instance classes.
When creating any new DocumentDB cluster, you MUST use these exact commands — default is serverless on engine 8.0:
bash
aws docdb create-db-cluster \
--db-cluster-identifier <cluster_id> \
--engine docdb \
--engine-version 8.0.0 \
--serverless-v2-scaling-configuration MinCapacity=1,MaxCapacity=16 \
--master-username adminuser \
--master-user-password '<password>' \
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \
--region <region>
aws docdb create-db-instance \
--db-instance-identifier <cluster_id>-instance \
--db-instance-class db.serverless \
--engine docdb \
--db-cluster-identifier <cluster_id> \
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \
--region <region>Credential handling: the command above takes the password inline for a self-contained workflow. For production, preferinstead of--manage-master-user-password— DocumentDB then generates the password and stores it in Secrets Manager with rotation, keeping it out of shell history. The two flags are mutually exclusive; when you use managed passwords, retrieve the credential with--master-user-password(the secret ARN is on the cluster'saws secretsmanager get-secret-value --secret-id <arn>) when building the connection string.MasterUserSecret
This applies to every create-cluster request regardless of phrasing. Switch to a fixed instance class ( etc.) only if the user explicitly describes sustained 24/7 high throughput or says "provisioned" or "instance-based". Never recommend Elastic Clusters unless the user has exhausted instance-based scaling options.
db.r8g.largeWhen the user asks which instance types are available in a specific region, or asks about instance class options, requirements, or regional availability: fetch the live DocumentDB instance classes page via or — do NOT answer from memory, as available instance classes vary by region and change with new launches. You can also verify programmatically: lists every available instance class and engine version combination for that region.
web_fetchaws___search_documentationaws docdb describe-orderable-db-instance-options --engine docdb --region <region>DocumentDB架构入门说明(用户有疑问时需明确解释):
- 无服务器:在普通基于实例的DocumentDB集群中使用作为实例类型。可自动扩展容量,无需选择实例类型,闲置时成本最高可降低90%。这是大多数工作负载的推荐默认配置。
db.serverless - 基于实例:固定实例类型(如、
db.r8g.large等)。适用于持续24/7高吞吐量的工作负载,且无服务器扩展开销不可接受的场景。db.r6g.xlarge - 弹性集群:用于水平分片的独立DocumentDB产品。与无服务器集群不同。弹性集群与基于实例的集群功能不兼容——它们不支持事务、变更流及众多聚合运算符。除非用户的分片需求已超出最大基于实例集群的能力,否则引导客户避免使用弹性集群。考虑到DocumentDB提供的广泛实例类型,几乎所有工作负载都可通过无服务器或基于实例的集群满足。
创建任何新DocumentDB集群时,必须使用以下精确命令——默认使用基于8.0引擎的无服务器配置:
bash
aws docdb create-db-cluster \\
--db-cluster-identifier <cluster_id> \\
--engine docdb \\
--engine-version 8.0.0 \\
--serverless-v2-scaling-configuration MinCapacity=1,MaxCapacity=16 \\
--master-username adminuser \\
--master-user-password '<password>' \\
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \\
--region <region>
aws docdb create-db-instance \\
--db-instance-identifier <cluster_id>-instance \\
--db-instance-class db.serverless \\
--engine docdb \\
--db-cluster-identifier <cluster_id> \\
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \\
--region <region>凭证处理:上述命令直接在命令行中传入密码,以实现自包含工作流。生产环境中,建议使用替代--manage-master-user-password——DocumentDB会生成密码并存储在Secrets Manager中自动轮换,避免密码出现在Shell历史记录中。这两个参数互斥;使用托管密码时,需通过--master-user-password(密钥ARN可在集群的aws secretsmanager get-secret-value --secret-id <arn>中找到)获取凭证以构建连接字符串。MasterUserSecret
此规则适用于所有创建集群的请求,无论用户表述方式如何。仅当用户明确描述持续24/7高吞吐量,或提及「预配置」「基于实例」时,才切换为固定实例类型(如等)。除非用户已穷尽基于实例的扩展选项,否则绝不推荐弹性集群。
db.r8g.large当用户询问特定区域可用的实例类型,或实例类型选项、要求、区域可用性时:通过或获取最新的DocumentDB实例类型页面——切勿凭记忆回答,因为可用实例类型因区域而异,且会随新版本发布而变化。也可通过编程方式验证:会列出该区域所有可用的实例类型与引擎版本组合。
web_fetchaws___search_documentationaws docdb describe-orderable-db-instance-options --engine docdb --region <region>Resource tagging (always apply on resource creation)
资源标签(创建资源时必须添加)
When creating any DocumentDB resource (, ), ALWAYS include these tags using the RDS list-of-records syntax (DocumentDB uses the RDS API):
create-db-clustercreate-db-instance--tags--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value={your-model-id}Example:
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=claude-sonnet-4-20250514Include these tags even if the user does not mention tagging, so that they can identify the resources created via this skill. If the user provides additional tags, append these to their tags rather than replacing them. The same applies when tagging via on existing resources.
add-tags-to-resource创建任何DocumentDB资源(、)时,必须使用RDS的记录列表格式语法添加以下标签(DocumentDB使用RDS API):
create-db-clustercreate-db-instance--tags--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value={your-model-id}示例:
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=claude-sonnet-4-20250514即使用户未提及标签,也必须添加这些标签,以便用户识别通过此工具包创建的资源。如果用户提供额外标签,需将这些标签追加到用户提供的标签之后,而非替换。对现有资源通过添加标签时同样适用此规则。
add-tags-to-resourceDo NOT execute (refuse, explain why, offer assessment instead)
禁止执行的操作(拒绝执行,解释原因,并提供评估方案)
- Delete cluster or instance: ,
delete-db-cluster— irreversible data lossdelete-db-instance - Failover: — production impact, use only under planned change control
failover-db-cluster - Major version upgrade: across major versions (4.0 → 5.0, 5.0 → 8.0) — requires prechecks and a rollback plan; use the MVU workflow in references/upgrade.md
modify-db-cluster --engine-version - Reboot: — production impact
reboot-db-instance
When refusing, explain why and offer the matching assessment workflow:
"I can't perform [action] because [reason]. I can run an assessment to help you decide. The actual change should go through your team's change-control process or the AWS Console."
- 删除集群或实例:、
delete-db-cluster——数据丢失不可逆转delete-db-instance - 故障转移:——影响生产环境,仅在计划变更控制下使用
failover-db-cluster - 主版本升级:跨主版本的(4.0 → 5.0、5.0 → 8.0)——需要预检查和回滚计划;使用references/upgrade.md中的MVU工作流
modify-db-cluster --engine-version - 重启:——影响生产环境
reboot-db-instance
拒绝执行时,需解释原因并提供对应的评估工作流:
「我无法执行[操作],因为[原因]。我可以运行评估来帮助您决策。实际变更应通过您团队的变更控制流程或AWS控制台执行。」
Common Tasks
常见任务
1. Verify Dependencies
1. 验证依赖项
Check that required tools are available in context before running any workflow.
Constraints:
- You MUST verify (or AWS CLI v2),
call_aws, andshellare available in contextweb_fetch - You MUST check ≥ 3.6 for wa_review.py, the
python3compat tool, and the index toolamazon-documentdb-tools - You MUST check ,
git,curl, andmongoshonly when a specific workflow requires themssh - You MUST inform the user of any missing tools and respect a decision to abort
- You MUST NOT invoke the tools during verification because that would trigger live AWS calls or cluster connections before the user confirms they are ready
- You SHOULD confirm credentials are valid with before live-analysis steps
aws sts get-caller-identity
运行任何工作流前,检查上下文环境中是否具备所需工具。
约束条件:
- 必须验证(或AWS CLI v2)、
call_aws和shell是否在上下文环境中可用web_fetch - 必须检查版本≥3.6,以支持wa_review.py、
python3兼容性工具和索引工具amazon-documentdb-tools - 仅当特定工作流需要时,才检查、
git、curl和mongosh是否可用ssh - 必须告知用户任何缺失的工具,并尊重用户终止操作的决定
- 验证过程中不得调用工具,因为这会在用户确认准备就绪前触发实时AWS调用或集群连接
- 在执行实时分析步骤前,应通过确认凭证有效
aws sts get-caller-identity
2. Classify the Request and Route
2. 分类请求并路由
Use the Decision Guide to pick one workflow.
Constraints:
- You MUST name the workflow you are routing to before loading the reference
- You MUST pass along cluster id, region, app name, source URI, and engine versions the user already supplied — they SHOULD NOT re-type these
- You MAY ask one clarifying question if a request straddles two workflows
- You MUST NOT fabricate workflow names for out-of-scope topics because doing so misleads the user about coverage
使用决策指南选择对应的工作流。
约束条件:
- 加载参考文档前,必须告知用户要路由到的工作流名称
- 必须传递用户已提供的集群ID、区域、应用名称、源URI和引擎版本——用户无需重复输入
- 如果请求同时涉及两个工作流,可提出一个澄清问题
- 不得为超出范围的主题编造工作流名称,以免误导用户
3. Execute the Workflow
3. 执行工作流
Load the matching and follow its section.
references/<workflow>.md## WorkflowConstraints:
- You MUST execute AWS CLI commands, DMS calls, queries, and bundled scripts yourself — the skill is an executor unless a step requires credentials the agent doesn't have
mongosh - You MUST explain what step is running, why, and which tool is being called before running it
- Extract required parameters from the conversation first — if ,
cluster_id, or other required values are already present, use them and proceed. Only ask for missing parameters, and ask for all missing ones together in a single prompt.region - You MUST support multiple input methods for parameters: direct input, file path, or URL
- You MUST validate parameter formats: cluster id (lowercase, hyphens), region (), ARN (
us-east-1), ISO-8601, CIDRarn:aws:... - You MUST NOT create or access credentials directly because the skill has no safe way to store or rotate them — use IAM roles, instance profiles, Secrets Manager ARNs, or delegate credential setup (e.g. /
aws sso login) to the useraws configure - You MUST NOT use with positional filesystem arguments because the MCP sandbox rejects them — pass JSON payloads inline or invoke scripts under
call_awsviascripts/shell - You MUST NOT grant wildcard IAM (or
Action: "*") or open security groups toResource: "*"in examples because those defaults cause customer production incidents0.0.0.0/0 - You SHOULD save artifacts to :
artifacts/{app-name}/,compatibility-report.md,migration-plan.md,upgrade-plan.mdwa_review_results.json - If multiple workflows ran, you MUST close with a 2–4 line synthesis linking the artifacts
Required parameters (ask upfront, together): — the cluster name the user refers to (e.g. "my cluster xyz" or "cluster xyz"), maps to in AWS CLI (lowercase-hyphens); (e.g. ); . Per workflow: (compat/migration), ( or for upgrade/compat), ( default, or etc. for provisioned instance-based).
cluster_id--db-cluster-identifierregionus-east-1app_namesource_uritarget_version5.08.0engine_classdb.serverlessdb.r8g.large加载对应的并遵循其部分的说明。
references/<workflow>.md## Workflow约束条件:
- 必须自行执行AWS CLI命令、DMS调用、查询和捆绑脚本——除非步骤需要工具包无法获取的凭证,否则工具包作为执行器运行
mongosh - 运行步骤前,必须解释当前运行的步骤、原因及调用的工具
- 先从对话中提取所需参数——如果、
cluster_id或其他必填参数已存在,直接使用并继续。仅询问缺失的参数,且一次性询问所有缺失的参数region - 必须支持多种参数输入方式:直接输入、文件路径或URL
- 必须验证参数格式:集群ID(小写、连字符)、区域(如)、ARN(如
us-east-1)、ISO-8601格式、CIDRarn:aws:... - 不得直接创建或访问凭证,因为工具包无法安全存储或轮换凭证——使用IAM角色、实例配置文件、Secrets Manager ARN,或委托用户设置凭证(如/
aws sso login)aws configure - 不得使用带位置文件系统参数的,因为MCP沙箱会拒绝此类参数——需将JSON负载内联传递,或通过
call_aws调用shell下的脚本scripts/ - 示例中不得授予通配符IAM权限(或
Action: "*"),也不得将安全组开放至Resource: "*",因为这些默认设置会导致客户生产环境事故0.0.0.0/0 - 应将产物保存至目录:
artifacts/{app-name}/、compatibility-report.md、migration-plan.md、upgrade-plan.mdwa_review_results.json - 如果运行了多个工作流,必须以2-4行的总结收尾,关联所有产物
必填参数(需提前一次性询问):——用户提及的集群名称(如「my cluster xyz」或「cluster xyz」),对应AWS CLI中的(小写连字符格式);(如);。各工作流额外参数:(兼容性评估/迁移)、(升级/兼容性评估为或)、(默认,或预配置基于实例的等)。
cluster_id--db-cluster-identifierregionus-east-1app_namesource_uritarget_version5.08.0engine_classdb.serverlessdb.r8g.large4. Critical Facts to Always Surface
4. 必须告知的关键事实
These DocumentDB-specific facts are required even when the agent's general MongoDB knowledge already produces a reasonable answer. Omitting them is the most common failure mode in production customer tickets.
For slow query / COLLSCAN diagnosis, you MUST tell the user ALL of the following five facts — never omit any:
- Run to confirm
db.collection.find({...}).explain()is the stage (the root cause), and after adding an index, re-runCOLLSCANto confirmexplain().IXSCAN - Create a compound index on (field order matching the query's equality predicates).
{userId: 1, status: 1} - DocumentDB uses left-prefix matching on compound indexes — field order matters because a compound index serves queries on
{A: 1, B: 1}alone ORA, but neverA + Balone. This is DocumentDB-specific behavior users must understand before picking an index layout.B - Check the index cache hit rate via CloudWatch after deployment — the (or the per-index equivalent) indicates whether the new index is staying hot in memory. A low ratio means the working set exceeds RAM and the index may need a larger instance class.
BufferCacheHitRatio - Verify with after the index is created to confirm the query now uses
explain()instead ofIXSCAN.COLLSCAN
For flexible-schema catalog / product design, you MUST tell the user ALL of the following four facts — never omit any:
- Use a single collection with common fields (name, price, category, sku) at the top level and variable attributes (size/color for shoes, RAM/storage for electronics) nested in an
productssubdocument.attributes - Create targeted indexes on and
categoryfor common query patterns.sku - Check current wildcard index support before advising. Wildcard indexes () may not be supported on all DocumentDB versions — verify current status at the MongoDB API compatibility page before advising. If unsupported: query patterns must be known upfront so targeted compound indexes can be created on specific paths under
attributes.$**.attributes - Discuss the tradeoff vs. separate collections per category. Single-collection design wins for cross-category queries and simpler maintenance; separate-collection-per-category wins for strict per-category query isolation and simpler per-category indexing — but requires the application to route queries to the right collection. Name both options so the user can choose.
For $graphLookup / MongoDB compatibility questions, you MUST tell the user ALL of the following three facts:
- Check current support status before advising.
$graphLookupis not supported on all DocumentDB versions — verify at the MongoDB API compatibility page before stating support status, as DocumentDB adds operators across versions. If the aws-documentation plugin is available, call$graphLookupto check the live status first.aws___search_documentation - If unsupported: recommend materialized ancestor paths — store each document's full path (array of parent IDs) so hierarchy queries become instead of recursive traversal. This is the canonical workaround and often the better design even when
find({ ancestors: "cat-123" })is available.$graphLookup - Offer alternatives for deep graph workloads — recursive in application code for moderate depth, or Amazon Neptune for deep or complex graph traversal.
$lookup
For Lambda → DocumentDB connection timeout, you MUST tell the user ALL of the following four facts:
- Lambda must be in the same VPC as the DocumentDB cluster, or reach it via VPC peering / Transit Gateway. DocumentDB is VPC-only — no public endpoint.
- Security group rule: inbound TCP on the DocumentDB cluster's SG, sourced from Lambda's security group ID (not a CIDR).
27017 - Connection string must include and the application MUST download the Amazon RDS global CA bundle (
tls=true) and reference it via the driver's TLS config. Also includeglobal-bundle.pemandreplicaSet=rs0.retryWrites=false - Test connectivity from an EC2 instance in the same subnet as Lambda first — that isolates Lambda-specific ENI issues from pure network/SG problems.
For any MongoDB migration to DocumentDB (including "I am migrating my MongoDB to AWS", "help me migrate", or any MongoDB-to-AWS migration request), you MUST tell the user ALL of the following six facts:
- Run the compatibility assessor FIRST — before anything else, clone amazon-documentdb-tools and run against the source MongoDB. This step is mandatory and must not be skipped or replaced with generic advice. Unsupported operators discovered after migration cause production outages.
python3 amazon-documentdb-tools/compat-tool/compat.py - Run the (also from
mongo-index-tool) to pre-create indexes on the DocumentDB target before starting the DMS task — DMS does not migrate indexes.amazon-documentdb-tools - Create source and target DMS endpoints with TLS enabled on both; target endpoint MUST use with
--ssl-mode verify-fullpointing at the RDS global bundle ARN.--certificate-arn - Create a task so you get an initial snapshot plus change-data-capture for near-zero-downtime cutover.
full-load-and-cdc - Monitor CloudWatch — watch and
CDCLatencySourceuntil they approach zero. Cut over only when lag is near zero.CDCLatencyTarget - Cut over by pointing application traffic at the DocumentDB endpoint, then stop the DMS task once traffic is drained from the source.
即使代理的通用MongoDB知识已能给出合理答案,也必须告知这些DocumentDB特有的事实。遗漏这些事实是生产环境客户工单中最常见的问题。
对于慢查询/COLLSCAN诊断,必须告知用户以下全部五个事实——不得遗漏任何一项:
- **运行**确认
db.collection.find({...}).explain()是执行阶段(根本原因),添加索引后,重新运行COLLSCAN确认使用explain()。IXSCAN - 创建复合索引(字段顺序与查询的相等谓词匹配)。
{userId: 1, status: 1} - DocumentDB对复合索引使用前缀匹配——字段顺序至关重要,因为复合索引可支持仅查询
{A: 1, B: 1}或同时查询A的请求,但绝不支持仅查询A+B的请求。用户在选择索引布局前必须理解这一DocumentDB特有行为。B - 部署后通过CloudWatch检查索引缓存命中率——(或等效的单索引指标)表明新索引是否常驻内存。比率低意味着工作集超出RAM容量,可能需要更大的实例类型。
BufferCacheHitRatio - 创建索引后通过验证确认查询现在使用
explain()而非IXSCAN。COLLSCAN
对于灵活架构目录/产品设计,必须告知用户以下全部四个事实——不得遗漏任何一项:
- 使用单个集合,将公共字段(名称、价格、类别、SKU)放在顶层,将可变属性(鞋子的尺寸/颜色、电子产品的RAM/存储)嵌套在
products子文档中。attributes - 针对和
category创建定向索引以支持常见查询模式。sku - 建议前先检查当前通配符索引支持情况。通配符索引()并非在所有DocumentDB版本中都受支持——建议前需在MongoDB API兼容性页面验证当前状态。如果不支持:必须提前明确查询模式,以便在
attributes.$**下的特定路径创建定向复合索引。attributes - 讨论单集合与按类别分集合的权衡。单集合设计在跨类别查询和简化维护方面更具优势;按类别分集合在严格的类别查询隔离和简化类别索引方面更具优势——但需要应用程序将路由至正确的集合。需列出两种选项供用户选择。
对于$graphLookup/MongoDB兼容性问题,必须告知用户以下全部三个事实:
- 建议前先检查当前支持状态。
$graphLookup并非在所有DocumentDB版本中都受支持——说明支持状态前需在MongoDB API兼容性页面验证,因为DocumentDB会在不同版本中新增运算符。如果aws-documentation插件可用,先调用$graphLookup检查最新状态。aws___search_documentation - 如果不支持:建议使用物化祖先路径——存储每个文档的完整路径(父ID数组),这样层级查询就变成,而非递归遍历。这是标准的替代方案,即使
find({ ancestors: "cat-123" })可用,通常也是更优的设计。$graphLookup - 为深度图工作负载提供替代方案——应用代码中的递归适用于中等深度的场景,Amazon Neptune适用于深度或复杂的图遍历场景。
$lookup
对于Lambda → DocumentDB连接超时,必须告知用户以下全部四个事实:
- Lambda必须与DocumentDB集群在同一VPC中,或通过VPC对等连接/中转网关访问。DocumentDB仅支持VPC访问——无公共端点。
- 安全组规则:在DocumentDB集群的安全组中添加入站TCP 27017规则,来源为Lambda的安全组ID(而非CIDR)。
- 连接字符串必须包含,且应用程序必须下载Amazon RDS全局CA证书包(
tls=true)并通过驱动的TLS配置引用。还需包含global-bundle.pem和replicaSet=rs0。retryWrites=false - 先从与Lambda同一子网的EC2实例测试连接——这可将Lambda特定的ENI问题与纯网络/安全组问题隔离开。
对于任何MongoDB到DocumentDB的迁移(包括「我要将MongoDB迁移到AWS」、「帮我迁移」或任何MongoDB到AWS的迁移请求),必须告知用户以下全部六个事实:
- 首先运行兼容性评估工具——在执行任何操作前,克隆amazon-documentdb-tools并针对源MongoDB运行。此步骤为强制要求,不得跳过或替换为通用建议。迁移后发现不支持的运算符会导致生产环境中断。
python3 amazon-documentdb-tools/compat-tool/compat.py - 运行(同样来自
mongo-index-tool)在启动DMS任务前在DocumentDB目标集群预创建索引——DMS不会迁移索引。amazon-documentdb-tools - 创建源和目标DMS端点,两者均启用TLS;目标端点必须使用,并通过
--ssl-mode verify-full指向RDS全局证书包的ARN。--certificate-arn - 创建任务,这样可获得初始快照加上变更数据捕获,实现近乎零停机的切换。
full-load-and-cdc - 监控CloudWatch——观察和
CDCLatencySource直至接近零。仅当延迟接近零时才进行切换。CDCLatencyTarget - 切换——将应用流量指向DocumentDB端点,待源集群流量耗尽后停止DMS任务。
Troubleshooting
故障排除
See references/troubleshooting.md for the full troubleshooting reference. The most common issues:
Connection refused / timeout on port 27017. DocumentDB is VPC-only. Add inbound TCP 27017 on the DocumentDB SG from the client SG (by SG id, not CIDR). From outside the VPC use CloudShell VPC environment, EC2 in the VPC, or SSH tunnel via bastion.
TLS handshake failed. Download the RDS global bundle and pass to mongosh when tunneling.
--tlsAllowInvalidHostnames"not master" / "not primary" or intermittent write errors. Connection string is missing (always ) or (DocumentDB does not support retryable writes).
replicaSet=rs0rs0retryWrites=falseDMS task refuses to start — "Test connection should be successful". Run for both endpoints and poll until both return . Target endpoint MUST use with for the RDS global bundle.
aws dms test-connectiondescribe-connectionssuccessful--ssl-mode verify-full--certificate-arnMVU command fails — "AllowMajorVersionUpgrade flag must be present" or "must explicitly specify a new DB cluster parameter group". Both and (when a custom PG is in use) a target-family are mandatory.
--allow-major-version-upgrade--db-cluster-parameter-group-nameUser asks for a destructive change. You MUST pause, state the consequence, and wait for explicit confirmation before deleting a cluster, dropping a collection, or forcing a failover — destructive actions on production DocumentDB can cause data loss or service disruption.
User hits a missing feature, unsupported operator, or expresses a future wish. When the user says "I wish DocumentDB supported X", "will DocumentDB ever support Y", or encounters a capability gap, proactively surface: "You can request this feature by emailing documentdb-pm@amazon.com with your AWS account ID, the feature you need, and your use case — the DocumentDB team reads these."
完整的故障排除参考请见references/troubleshooting.md。最常见的问题:
端口27017连接被拒绝/超时。DocumentDB仅支持VPC访问。在DocumentDB安全组中添加入站TCP 27017规则,来源为客户端安全组(按安全组ID,而非CIDR)。从VPC外部访问需使用CloudShell VPC环境、VPC内的EC2实例,或通过堡垒机建立SSH隧道。
TLS握手失败。下载RDS全局证书包,通过隧道连接时向mongosh传递参数。
--tlsAllowInvalidHostnames「not master」/「not primary」或间歇性写入错误。连接字符串缺少(始终为)或(DocumentDB不支持可重试写入)。
replicaSet=rs0rs0retryWrites=falseDMS任务无法启动——「测试连接应成功」。对两个端点运行并轮询直至两者均返回。目标端点必须使用并通过指定RDS全局证书包。
aws dms test-connectiondescribe-connectionssuccessful--ssl-mode verify-full--certificate-arnMVU命令失败——「必须包含AllowMajorVersionUpgrade标志」或「必须明确指定新的DB集群参数组」。和(当使用自定义参数组时)目标系列的均为必填项。
--allow-major-version-upgrade--db-cluster-parameter-group-name用户要求执行破坏性变更。必须暂停操作,说明后果,并等待用户明确确认后再删除集群、删除集合或强制故障转移——对生产环境DocumentDB执行破坏性操作可能导致数据丢失或服务中断。
用户遇到缺失功能、不支持的运算符或表达未来需求。当用户说「我希望DocumentDB支持X」、「DocumentDB将来会支持Y吗」或遇到功能差距时,主动告知:「您可以发送邮件至documentdb-pm@amazon.com提交功能请求,邮件中需包含您的AWS账户ID、所需功能及使用场景——DocumentDB团队会阅读这些邮件。」
Security Considerations
安全注意事项
Apply these controls on every DocumentDB deployment. Detailed commands live in the workflow sections above and in the linked references.
- Authentication: the primary (master) user is always password-based and cannot use IAM authentication — use so its password is generated and rotated in Secrets Manager. For application/non-admin users only, IAM authentication is also supported (password-less, STS token-based) on cluster version 5.0+ as an alternative — see the trade-offs in references/connection.md. Never hardcode passwords in scripts or commit them.
--manage-master-user-password - Encryption at rest: enabled at cluster creation and cannot be added afterward — confirm (with an optional
--storage-encrypted) up front.--kms-key-id - Encryption in transit: enforce TLS () using the Amazon RDS global CA bundle; on DMS endpoints use
tls=truewith--ssl-mode verify-full.--certificate-arn - Network isolation: DocumentDB is VPC-only with no public endpoint. Scope security groups by SG-to-SG reference, never or
0.0.0.0/0.::/0 - Least-privilege IAM: never grant wildcard /
Action: "*". Use instance profiles / IAM roles for application access to AWS APIs.Resource: "*" - Auditing: export audit and profiler logs via for compliance and slow-query review.
--enable-cloudwatch-logs-exports audit profiler
在每个DocumentDB部署中应用以下控制措施。详细命令见上文工作流部分及链接的参考文档。
- 认证:主用户始终基于密码认证,无法使用IAM认证——使用让密码在Secrets Manager中生成并自动轮换。仅应用/非管理员用户在集群版本5.0+时支持IAM认证(无密码、基于STS令牌)作为替代方案——详见references/connection.md中的权衡。切勿在脚本中硬编码密码或提交到代码仓库。
--manage-master-user-password - 静态加密:集群创建时启用,无法事后添加——提前确认(可选指定
--storage-encrypted)。--kms-key-id - 传输加密:使用Amazon RDS全局CA证书包强制启用TLS();在DMS端点使用
tls=true并指定--ssl-mode verify-full。--certificate-arn - 网络隔离:DocumentDB仅支持VPC访问,无公共端点。安全组规则按安全组到安全组的引用配置,绝不开放至或
0.0.0.0/0。::/0 - 最小权限IAM:绝不授予通配符/
Action: "*"权限。使用实例配置文件/IAM角色让应用程序访问AWS API。Resource: "*" - 审计:通过导出审计和分析日志,用于合规性检查和慢查询审查。
--enable-cloudwatch-logs-exports audit profiler
Additional Resources
额外资源
- Amazon DocumentDB Developer Guide · MongoDB API compatibility reference
- DocumentDB pricing · instance classes · DocumentDB Cost Estimator — workload-aware sizing tool that takes MongoDB ops/sec and I/O inputs and produces a DocumentDB vs MongoDB cost comparison
- DocumentDB Serverless · vector search
- Backup and restore · Well-Architected pillars
- AWS DMS MongoDB source · DocumentDB target
- amazon-documentdb-tools (compat tool, index tool, MVU CDC migrator)
- Related skills: ,
amazon-aurora,rds-db2,rds-oracle,rds-sqlserveramazon-neptune - Missing a feature or have feedback? Email documentdb-pm@amazon.com with your AWS account ID, the feature or capability you need, and your use case — the DocumentDB team reads these.
- Amazon DocumentDB开发者指南 · MongoDB API兼容性参考
- DocumentDB定价 · 实例类型 · DocumentDB成本估算工具——工作负载感知型规划工具,接受MongoDB每秒操作数和I/O输入,生成DocumentDB与MongoDB的成本对比
- DocumentDB无服务器 · 向量搜索
- 备份与恢复 · Well-Architected支柱
- AWS DMS MongoDB源 · DocumentDB目标
- amazon-documentdb-tools(兼容性工具、索引工具、MVU CDC迁移工具)
- 相关工具包:、
amazon-aurora、rds-db2、rds-oracle、rds-sqlserveramazon-neptune - **缺少功能或有反馈?**发送邮件至documentdb-pm@amazon.com,包含您的AWS账户ID、所需功能或能力及使用场景——DocumentDB团队会阅读这些邮件。",