docs(backend): document MongoDB connection and fail fast when it is missing - #480
Open
peaceshallom37-rgb wants to merge 1 commit into
Open
Conversation
…issing Mongoose models are used across the backend (content delivery, notifications, offline sync, quizzes, etc.) and index synchronization runs at startup, yet the MongoDB connection string was undocumented while .env.example only covered PostgreSQL and Redis. A fresh deployment following the documented setup would silently never connect to MongoDB. - Add MONGODB_URI (and the Postgres-vs-Mongo split) to .env.example. - Fail startup when Mongoose models are registered but no Mongo URI is configured, so index sync and Mongoose-backed routes never silently run without a database. - Document the Postgres-vs-Mongo division of responsibility in backend/README.md. Closes AetherEdu#471
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #471
Summary
The backend connects to MongoDB via
MONGODB_URI/MONGO_URI(ensureMongooseIndexesinbackend/src/index.ts) and loads dozens of Mongoose models, but the connection string was undocumented —.env.exampleonly listed PostgreSQL and Redis. A fresh deployment following the documented setup would never connect to MongoDB, and index sync + Mongoose-backed routes would silently behave as if no database existed.Changes
.env.example— adds aMONGODB_URIentry under Database Configuration, with a note explaining the Postgres-vs-Mongo split.backend/src/index.ts—ensureMongooseIndexes()now fails fast (throws before the server starts) when Mongoose models are registered but no MongoDB URI is configured, instead of silently returning. Connection handling when a URI is set is unchanged.backend/README.md— documents the division of responsibility: PostgreSQL is the primary relational store (users, enrollments, payments, courses, migrations); MongoDB is the document store for Mongoose-backed services (content delivery, notifications, offline sync, quizzes, translations, whiteboard, etc.), and is required at startup.Verification
npm run typecheckpasses.main(verified by stashing; e.g.@ts-ignoreban errors inindex.tsand afeatureFlags.tsimport failure intests/api.test.js).startServer(), which only runs when the module is the entrypoint (require.main === module), so tests that import the app are unaffected.