Open-Source Wikis

/

MongoDB

/

How to contribute

/

Tooling

mongodb/mongo

Tooling

Building, linting, and testing MongoDB requires a small constellation of tools. Most of them are wrapped by Bazel and Poetry, so a one-time setup is usually enough.

Bazel

The build system is Bazel, driven from MODULE.bazel, WORKSPACE.bazel, and per-directory BUILD.bazel files. Custom rules and toolchains live under bazel/.

Key entry points:

  • bazel build install-mongod — builds the database server.
  • bazel build install-mongos — the sharding router.
  • bazel build install-devcore — the common combo (mongod, mongos, jstestshell).
  • bazel test //src/mongo/... — runs all C++ unit-test targets.
  • bazel run format — runs the formatter pipeline.

The version of Bazel used is pinned in .bazelversion. The bazelisk-style launcher (installed by buildscripts/install_bazel.py) reads it.

The configuration files of interest:

Poetry

Python dependencies for buildscripts/, evergreen/, and modules_poc/ are managed by Poetry. The lockfile poetry.lock pins everything; pyproject.toml declares groups (main, lint, test, etc.).

Sync the virtualenv:

buildscripts/poetry_sync.sh

The script creates .venv/ if it doesn't exist and installs the matching pinned dependencies. The script and lockfile are described in docs/poetry_execution.md.

Lint and format

Tool Coverage
clang-format (.clang-format) C++ formatting.
clang-tidy (.clang-tidy.in) C++ static analysis. Custom checks defined in buildscripts/clang_tidy/.
eslint (eslint.config.mjs) JavaScript (the jstestshell and jstests/ code).
prettier (.prettierrc) Markdown, JSON, JS formatting.
cspell (cspell.json) Spell check for source comments and docs.
mypy (.mypy.ini) Type checking for buildscripts/.
pylint (Poetry-managed) Python style.
ruff (Poetry-managed) Python lint + format.

The orchestrator is bazel run format (and bazel run lint). Targeted checks:

buildscripts/clang_format.py format-my   # only files changed in this branch
buildscripts/clang_tidy.py               # run clang-tidy locally
buildscripts/eslint.py format-my         # JS lint on changed files

The lint configuration matrix is reflected in evergreen/ task scripts: each lint runs as a dedicated Evergreen task on patch builds.

IDL compiler

The IDL compiler turns YAML schemas into C++ headers and sources. It lives at buildscripts/idl/idl/ and is invoked as a Bazel rule. The generated code lands in bazel-bin/.../*.gen.h and *.gen.cpp. See IDL and docs/idl.md.

To check that an IDL change does not break wire compatibility:

bash evergreen/check_idl_compat.sh

Modules tooling

The modules_poc/ tree contains:

  • modules_poc/modules.yaml — the module assignments (one block per module, listing globs).
  • modules_poc/merge_decls.py — runs the scanner across the codebase and writes merged_decls.json.
  • modules_poc/private_headers.py — bulk-marks de-facto-private headers with MONGO_MOD_PRIVATE.
  • modules_poc/browse.py — TUI for inspecting module visibility, finding violations, and labeling APIs.
  • modules_poc/mod_diff.py — generates a PR comment summarizing API visibility changes.

The full workflow is described in docs/modularity.md and on the Modularity page.

Resmoke

buildscripts/resmoke.py is the JavaScript and unit-test runner. The bulk of its logic is in buildscripts/resmokelib/. Suite definitions live under buildscripts/resmokeconfig/suites/. See Testing for usage.

Evergreen

CI configuration lives under evergreen/. The top-level etc/evergreen*.yml files describe build variants and tasks; each task is implemented as a shell script under evergreen/. Notable scripts:

  • evergreen/bazel_compile.sh — compile task for any platform.
  • evergreen/bazel_test.sh — run a resmoke suite.
  • evergreen/check_idl_compat.sh — IDL compatibility gate.
  • evergreen/devcontainer_test.sh — verify the devcontainer image.

Code generation

A few code generators produce C++ in addition to IDL:

  • Cheetah templates (buildscripts/cheetah_source_generator.py) — templated C++ generation.
  • Mongo config header (src/mongo/mongo_config_header.py) — produces the build-time config.h.
  • clang-tidy config (buildscripts/clang_tidy_config_gen.py) — splits the in-tree tidy config across the supported toolchains.

Generated files are not checked in; they live in bazel-bin/.

Useful one-liners

# Format only my changes
buildscripts/clang_format.py format-my

# Run a single resmoke test
buildscripts/resmoke.py run --suites=core jstests/core/find/find1.js

# Re-scan modules and view violations
modules_poc/merge_decls.py
modules_poc/browse.py

# Check that no command's API surface changed
bash evergreen/check_idl_compat.sh

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Tooling – MongoDB wiki | Factory