fix: use container-internal env vars in mongo healthcheck#259
Conversation
mongosh 2.6.0 + MongoDB 8.0 produces "storedKey mismatch" when the
connection URI includes a database path (localhost/integr8scode) while
--authenticationDatabase points to a different db (admin). Switching to
explicit --host/--port flags with --username/--password avoids this.
Also replaces ${MONGO_PASSWORD:-...} host-side interpolation (which
mangles passwords containing $, `, " via the container's sh) with
$$MONGO_INITDB_ROOT_USERNAME / $$MONGO_INITDB_ROOT_PASSWORD — the $$
escape tells docker-compose to emit a literal $ so the container shell
expands the variables from the mongo container's own environment, where
they are already set by the environment: block.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe MongoDB healthcheck in docker-compose.yaml was updated to use an explicit mongosh invocation with host 127.0.0.1, port 27017, and root credentials derived from environment variables, evaluating db.adminCommand("ping") instead of piping a shell-based ping command. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes the MongoDB healthcheck command in docker-compose.yaml to use container-internal environment variables ($$MONGO_INITDB_ROOT_USERNAME / $$MONGO_INITDB_ROOT_PASSWORD) instead of host-level shell variables (${MONGO_USER} / ${MONGO_PASSWORD}), ensuring the healthcheck works reliably regardless of the host environment.
Changes:
- Replaces shell-interpolated host env vars with Docker-escaped (
$$) container-internal env vars - Switches from
echo ... | mongoshtomongosh --evalstyle invocation
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.



Summary by cubic
Fix MongoDB healthcheck in docker-compose by using explicit host/port and container env vars for credentials. This avoids the “storedKey mismatch” on mongosh 2.6.0 + MongoDB 8 and prevents password mangling.
Written for commit d06cdce. Summary will update on new commits.
Summary by CodeRabbit