mongodb - vercel

Project: Next.js + React project
Structure: App Router

I connected the project to MongoDB and continued development locally without using Docker since I am the only developer. It connects and works fine on my local machine. However, when I deploy it to Vercel, it tries to connect to the database, but after 10 seconds it cancels the operation because there's a 10-second limit on Vercel, resulting in all my APIs returning a 504 error.

  • MongoDB connection string is correct
  • MongoDB network access is open to all IPs
  • Connection string is set in Vercel environment variables

    -Task timed out after 10.02 seconds

More than likely you have a bad or missing connection string saved when deploying the app, double check it

If not, check the networking settings in vercel to see if your app’s ip is allowed to access the database

Vercel runs serverless and mongodb likely has no load balancer in front of it

You'll also want to keep an eye on the Vercel functions Max duration which on the Hobby plan is 10s and even if you upgrade I think you'll need to specify if you want longer:…

I ran into this a ton when running longer AI tasks / calling out to external serviced and had to create a webhook system 🙃