MongoDB checklist¶
Copy this list into a pull request, design review or project kickoff and tick what applies. Rules are grouped by level and sorted by score (criteria). Each links to the file that explains it and cites its sources. Automatable names tools that can check the rule in CI (see the file's "How to enforce" section).
Also apply the general checklist.
This file is generated by python3 scripts/rank.py fix from the guidelines. Don't edit it by hand.
Strongly recommended (9–10)¶
-
MONGO-11(9) Self-managed: bind MongoDB to private interfaces, firewall its port so that only application hosts can reach it, and turn on access control, which is off by default. Atlas: never add0.0.0.0/0to the IP access list, and connect staging and production projects through private endpoints. (specific/mongodb) Automatable: Atlas Resource Policies. -
MONGO-12(9) Never pass request data into a query filter or update document as an object: check that each value is a scalar of the expected type, or wrap it in$eq, so that a client can't send query operators such as{"$ne": null}. (specific/mongodb) Automatable: CodeQL, Database query built from user-controlled sources.
Recommended (6–8)¶
-
MONGO-1(8) Design each collection from the application's read and write patterns: embed data that is read or updated together, and reference data that grows without bound, has many items on the child side, is written at different times or exists on its own. (specific/mongodb) -
MONGO-2(8) Keep documents bounded: cap arrays with the subset pattern or move their items to a separate collection, and move fields that aren't read together into separate documents. (specific/mongodb) -
MONGO-7(8) Write data you can't lose withw: "majority", the default, on replica sets with at least three data-bearing voting members, and read from the primary with"majority"read concern where a client must read its own writes. (specific/mongodb) -
MONGO-13(8) Give each application its own database user with roles scoped to the databases and actions it needs, never a cluster-wide or administrator role, and require TLS on every connection (SEC-5,SEC-13). On Atlas, authenticate production workloads with Workload Identity Federation, AWS IAM or X.509 certificates; Atlas recommends password (SCRAM) users only for development and test. (specific/mongodb) Automatable: Atlas Resource Policies. -
MONGO-15(8) Back up production clusters with point-in-time recovery, keep a copy in a second region, and test restores regularly (DATA-8). On Atlas, turn on Cloud Backup with Continuous Cloud Backup, multi-region snapshot distribution and a Backup Compliance Policy. (specific/mongodb) -
MONGO-3(7) When the shape of a document changes, add aschemaVersionfield, and make the code's queries and updates handle every version that can still be in the collection. (specific/mongodb) -
MONGO-4(7) Once a collection's schema is established, add a$jsonSchemavalidator and keep the default behavior, which rejects invalid inserts and updates. (specific/mongodb) -
MONGO-5(7) Create an index for every frequent query, order compound index keys by the ESR guideline (equality, then sort, then range), and check each query withexplain("executionStats"): it should use an index scan (IXSCAN) and examine about as many documents as it returns. (specific/mongodb) Automatable:notablescanserver parameter. -
MONGO-8(7) Use multi-document transactions only where several documents must change atomically, run them with the driver's callback API, which retries transient errors, and keep each one well under the 60-second default limit. (specific/mongodb) -
MONGO-9(7) Leave retryable writes on, the driver default, and handle what they don't cover: retry failed operations with exponential backoff where that is safe (OPS-3), and make multi-document updates and deletes idempotent. (specific/mongodb) -
MONGO-10(7) Create oneMongoClientper process when it starts, outside request and serverless handlers, and reuse it for every operation; sizemaxPoolSizefrom the number of concurrent requests, starting at 110–115% of the typical number. (specific/mongodb) -
MONGO-14(7) Never build$where,$functionor$accumulatorexpressions from user input, and turn server-side JavaScript off when the application doesn't use it:--noscriptingorsecurity.javascriptEnabled: falseon self-managed servers, and the Allow Server-Side JavaScript setting on Atlas. (specific/mongodb) Automatable: Semgrepmongodb-nosqlirule. -
MONGO-16(7) Choose the upgrade path on purpose. On Atlas clusters that upgrade automatically, declare the Stable API version in a strict client; elsewhere, test each new major version on a staging deployment first, upgrade before the current one reaches end of life, and raise the feature compatibility version only after testing, because after that you can't downgrade. (specific/mongodb)
Conditional (1–5)¶
-
MONGO-6(5) If you shard a collection, choose a shard key with high cardinality, evenly spread and non-monotonic values, that most queries include, so that they go to one shard. (specific/mongodb)