Skip to content

Fix backend startup on MongoDB connection failure#715

Closed
saurabhhhcodes wants to merge 1 commit into
aryandas2911:mainfrom
saurabhhhcodes:codex/fix-connectdb-exit-on-failure
Closed

Fix backend startup on MongoDB connection failure#715
saurabhhhcodes wants to merge 1 commit into
aryandas2911:mainfrom
saurabhhhcodes:codex/fix-connectdb-exit-on-failure

Conversation

@saurabhhhcodes
Copy link
Copy Markdown
Contributor

Summary

  • log the actual MongoDB connection error message during startup
  • terminate the backend process when the initial database connection fails
  • prevent the API server from continuing in a partially initialized state without a working database

Why

If MONGO_URI is missing, invalid, or MongoDB is unavailable, continuing startup makes later API failures harder to diagnose. Failing fast gives maintainers and deployments a clear signal that the backend is not ready.

Validation

  • /Users/saurabhkumarbajpaiai/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node --check backend/config/db.js passed
  • git diff --check passed

GSSoC labels requested

If accepted, please add gssoc:approved, level:beginner, quality:clean, and type:bug / type:backend if they match the project label scheme.

@saurabhhhcodes saurabhhhcodes force-pushed the codex/fix-connectdb-exit-on-failure branch from 521088b to 2923461 Compare May 19, 2026 12:38
@saurabhhhcodes
Copy link
Copy Markdown
Contributor Author

Updated this PR against the latest main. The original fail-fast behavior is now already present upstream, so I kept the PR useful by adding one small follow-up guard: fail immediately with a clear message when MONGO_URI is not configured before calling mongoose.connect.

Validation after the update:

  • git diff --check origin/main...HEAD
  • node --check backend/config/db.js
  • backend/node_modules/.bin/eslint backend/config/db.js

All passed locally. If this remains useful for GSSoC, please consider gssoc:approved, level:beginner, quality:clean, and type:bug / backend-equivalent labels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants