A debugging story: when your database "isn't connected"... except it is.

Building a job application tracker with Next.js + MongoDB + Mongoose, and I hit a bug that taught me more than any tutorial could.
The symptom: I'd defined my Mongoose schemas (Board, Column, JobApplication), wired up the logic to create them on user signup, and checked MongoDB Atlas... nothing. Empty. No collections, no documents. My first thought: "Is my database even connected?"
Step 1 — Prove the connection itself.
Instead of guessing, I wrote a standalone test script that connected directly, listed existing collections, and wrote a throwaway document. If that worked, the problem wasn't my URI or my cluster — it was somewhere in my app logic. It worked. Connection confirmed. So the bug was in my code, not MongoDB.
Step 2 — Chase it down layer by layer.
Turned out there wasn't just one bug — there were several, stacked on top of each other: A missing await on a findOne() call meant my "check if board exists" logic always evaluated as true (a Query object is truthy even before it resolves), so my creation logic silently never ran. My test script wasn't reading my env variables — because my file was named .env.local, and plain dotenv only looks for .env by default. I'd copy-pasted my Mongoose model registration pattern across three schema files, but didn't update the registry key each time — so Column.ts and JobApplication.ts were checking mongoose.models.Board instead of their own names. One typo like that silently corrupts your entire model registry. A singular/plural mismatch ("JobApplication" vs "JobApplications") between the check and the registration line meant the model check and the actual registration were never talking about the same thing.
Step 3 — Fix, then verify against reality, not assumptions.
After fixing the model registration and confirming my databaseHooks in Better Auth was correctly wired to run initializeUserBoard() on every new signup, I still didn't trust it — so I created a brand new test user through the actual frontend, not just my test script, and refreshed Atlas. That's when I finally saw it: boards, columns, and jobapplications collections, populated exactly as expected. The real lesson: none of these bugs threw loud errors. They failed silently — a wrong boolean, a missing file lookup, a mismatched string. As a beginner in backend work, this was the first time I really understood that "nothing is happening" is a symptom you have to investigate methodically, not a dead end. Isolate the layer, test it in isolation, then move to the next layer.
Small typos in "glue code" are often the real culprits — not the big, scary parts you're afraid of as a beginner.
Please if you have any questions, I will try my best to answer. Thank you 😊
Top comments (1)
Heads up, it is a tutorial I was following but the author was very fast and mostly did copy and paste for this section of the code so I had to figure it out when the errors occurred.