Replies: 2 comments
-
I am having a similar issue. My mongo db connection worked flawlessly with pages router. In app router I am actually getting a different error and it's not even connecting to the database at all. It says cannot read base. I've tried so many different things to make this work. Re writing connection scripts, using different versions of mongoose, moving folders to be included in app dir, all sorts of things. I am using mongoose, next 14.0.4, mongodb atlas, and typescript. Perhaps our issues can both be fixed with this pr but I'm not sure. |
Beta Was this translation helpful? Give feedback.
-
duplication of #11178 |
Beta Was this translation helpful? Give feedback.
-
Question
When I connect to MongoDB (via MONGODB_URI env variable, via the node driver) from my Vercel-deployed app, I get intermittent errors (MongoServerSelectionError) that present as 500 errors in my Vercel-deployed app. The errors go away on refresh.
An example of the error is:
Just to be clear, the connection string and credentials work and are correct as it does connect properly when errors are not there, but when errors that I describe above do occur, it crashes the entire app.
I've written about this in detail in the MongoDB community here (https://www.mongodb.com/community/forums/t/no-way-to-avoid-replicasetnoprimary-errors/243498).
I've also been in contact with MongoDB support and they said that there are no problems with the Mongo cluster itself.
Moreover, upon further research, it seems that this is a common problem when trying to connect to MongoDB from Vercel. For example, here (https://www.mongodb.com/community/forums/t/intermittently-getting-mongoserverselectionerror-error-on-my-next-js-vercel-deployment/242470).
I'd like to solve this problem, or at the very least, not have my entire app crash with a 500 due to the error, as it currently does.
Please help.
Beta Was this translation helpful? Give feedback.
All reactions