This is the official MongoDB Specifications repository containing technical specifications for MongoDB drivers and associated products. It includes:
- Specification documents (Markdown in
source/) - Unified test format files (YAML + auto-generated JSON) consumed by all MongoDB drivers
- Documentation published via MkDocs and ReadTheDocs
pip install -r source/requirements.txt # Install Python deps
mkdocs serve # Live preview at localhost:8000
mkdocs build --strict # Build (CI mode, no warnings allowed)pre-commit install # Set up hooks
pre-commit run --all-files # Run all hooks manually
pre-commit run --all-files --hook-stage manual shellcheck # Run shellcheck manuallyCI will fail if JSON files are out of date with their YAML sources. Always run make -C source after editing YAML test
files.
npm install -g js-yaml # Required once
make -C source # Convert all YAML test files to JSONmake update-schema-latest -C sourceSome specs include Python scripts that generate test files. These often live alongside their respective specs rather than in a single directory. Examples:
python source/server-discovery-and-monitoring/tests/errors/generate-error-tests.py # SDAM error tests
python source/client-side-encryption/etc/generate-corpus.py # Client-side encryption corpus tests
python source/etc/generate-handshakeError-tests.py # Handshake error testsA general pattern: look for generate-*.py scripts in a spec's etc/ or tests/ subdirectory.
Each subdirectory under source/ is a specification area (e.g., crud/, transactions/, auth/). Specs are written
in GitHub Flavored Markdown at 120-character line width, following the
MongoDB Documentation Style Guidelines. Each spec typically contains:
*.md— the specification itself, with a## Changelogsection at the bottomtests/— YAML test files (human-editable) and auto-generated JSON (never edit manually)
Each spec file contains its own ## Changelog section (not a separate file). Entries are dated and prepended at the
top:
## Changelog
- 2026-05-13: Describe the change made.
- 2024-03-01: Previous change.The unified test format (source/unified-test-format/) defines a YAML/JSON schema for cross-driver tests. Key rules:
- Always use the lowest possible schema version that satisfies a test's requirements — do not default to the latest
- YAML files are the source of truth; JSON files are auto-generated and committed
- Schema versions live in
source/unified-test-format/schema-*.json;schema-latest.jsonmust match the highest version (runmake update-schema-latest -C sourceto update it) - CI validates test files against the declared schema version using
ajv-cli. Using any fields from a newer schema version than declared will fail validation.
- YAML test files are human-editable and located in
tests/subdirectories - JSON files are generated automatically by CI from YAML — never edit
.jsontest files manually - Use
runOnRequirementsto restrict tests to specific server versions/topologies - Topologies to consider: standalone, replica set, sharded cluster, load balanced
MkDocs with pymdown-extensions and mkdocs-github-admonitions-plugin. The navigation is largely auto-generated via
scripts/generate_index.py. The build must pass in --strict mode (no warnings).
Do not modify existing tests unless they are testing incorrect behavior. Default to creating new tests or new test files instead of altering existing ones.
- Test files can only be deleted once no driver runs them anymore.
- For spec changes that remove functionality: use
runOnRequirements(unified tests) or have drivers skip the test (non-unified tests like SDAM). - Outdated prose tests must not be removed — mark them as such (e.g., strikethrough or Removed).
Always use relative numbered bullets (1.) for prose tests. New tests must be appended at the end of the list,
since drivers may reference existing tests by number.
Only test functionality directly related to the new spec requirements. Omit irrelevant fields in command expectations. This makes tests more resilient against future spec updates.
| Tool | Purpose |
|---|---|
mdformat |
Auto-formats Markdown (GFM, 120-char lines) |
markdown-link-check |
Validates links |
codespell |
Spell checking |
shellcheck |
Shell script linting |
All checks run via pre-commit. CI enforces them in .github/workflows/lint.yml.
Per the PR template and project workflow:
- Title must include a DRIVERS ticket (e.g.,
DRIVERS-1234) - Update the
## Changelogsection in each modified spec file - Test changes in at least one language driver
- Include links to the driver implementation PRs in the PR description (e.g.,
Python implementation: https://github.com/mongodb/mongo-python-driver/pull/…) - Tests must pass against all supported server versions and topologies
From source/driver-mantras.md:
- Prefer MUST over SHOULD — wishy-washy specs produce incompatible drivers
- Be topology-agnostic wherever possible
- Minimize configuration options ("No Knobs" principle)
- Check wire protocol version, not server version
- Follow semantic versioning for behavior changes
- Design for the next release, not hypothetical future ones ("Defy augury")