MongoDB "mongosh: command not found" in CI
The shell could not find mongosh. The modern MongoDB Shell is a standalone package, not bundled with a mongo service container or with the mongodb Node driver, so a runner without it fails any mongosh step.
What this error means
A step running mongosh ... fails with "mongosh: command not found" and exit code 127, even when a mongo service container is present.
/home/runner/work/_temp/script.sh: line 1: mongosh: command not found
Error: Process completed with exit code 127.Common causes
mongosh is not installed on the runner
The service container ships mongod, but the runner host has no mongosh binary on PATH.
Relying on the legacy mongo shell
The old mongo shell was removed in MongoDB 6+, so scripts that assume it also break; the replacement is mongosh.
How to fix it
Install mongosh in a step
- Add the MongoDB apt repository, or download the mongosh tarball.
- Install
mongodb-mongoshsomongoshis on PATH. - Run your shell steps after installation.
wget -qO- https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb.gpg
echo "deb [signed-by=/usr/share/keyrings/mongodb.gpg] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update && sudo apt-get install -y mongodb-mongoshRun mongosh inside the mongo image
If a mongo container is running, exec mongosh inside it instead of on the host.
docker exec <mongo-container> mongosh --eval 'db.adminCommand({ping:1})'How to prevent it
- Install mongosh explicitly; do not assume it exists on the runner.
- Use
mongosh, not the removed legacymongoshell. - Pin the mongosh version for reproducible steps.