mongodb/mongo
jstestshell
jstestshell is the JavaScript shell embedded in this repository. It is the runtime for the jstests/ regression suite and a developer-facing tool for ad-hoc work against a mongod or mongos. The user-facing mongosh is a separate Node-based project; what lives here is the in-tree shell that links against the same C++ libraries the server uses.
Purpose
jstestshell provides:
- A SpiderMonkey-based JavaScript runtime (
src/mongo/scripting/). - BSON,
OperationContext-free, but otherwise full access to the server's BSON, regex, and binary-type libraries. - A "client" object that talks the wire protocol to a server.
- Helpers for spinning up replica sets and sharded clusters in tests (
ReplSetTest,ShardingTest,MongoRunner).
It does not include the modern shell UI features (autocompletion, color, syntax highlighting, line-editing) of mongosh. The split happened when mongosh was extracted into its own repository, leaving this in-tree binary focused on test usage.
Entry point
The shell's entry point is in src/mongo/shell/, with the JS engine integration under src/mongo/scripting/. Helpers used by jstests/ are loaded from jstests/libs/.
How tests use it
graph LR
Resmoke[buildscripts/resmoke.py] -->|spawn| Fixture[mongod / replica set / sharded cluster]
Resmoke -->|spawn| Shell[jstestshell]
Shell -->|wire protocol| Fixture
Shell -->|load| TestFile[jstests/.../foo.js]
Shell -->|load| Helpers[jstests/libs/*.js]Resmoke launches the topology, then runs each test file in a fresh shell process. Helpers like ReplSetTest and ShardingTest come from jstests/libs/replsettest.js and jstests/libs/sharding/sharding_test.js.
Key source files
| File | Purpose |
|---|---|
src/mongo/scripting/ |
The SpiderMonkey integration and JS-to-C++ bindings. |
src/mongo/shell/ |
Shell main, command-line parsing, and JS context setup. |
src/mongo/client/ |
The C++ client used internally to talk to mongod/mongos. |
jstests/libs/ |
JavaScript helpers shared across tests. |
Relationship to mongosh
The user-facing mongosh is a separate project at https://github.com/mongodb-js/mongosh, written in Node.js. New users should download it from https://www.mongodb.com/try/download/shell. jstestshell exists in this repo to keep the test runtime aligned with the server binaries it tests — both link against the same C++ wire-protocol client and the same BSON code, so tests don't see "shell skew" between releases.
Entry points for modification
Most test-facing changes are made in jstests/libs/. JS-to-C++ bindings (e.g. exposing a new BSON type or a new admin helper) are added under src/mongo/scripting/mozjs/. Embedding decisions (signal handling, command-line flags) live in src/mongo/shell/.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.