Unable to connect MongoDB in Vercel Deployment - NEXTJS
Answered
Ibizan Hound posted this in #help-forum
Ibizan HoundOP
Project: Nextjs + React project
Structure App Router
I connected MongoDB to the project and continued to develop in my locale, I did not use docker because I developed it as a single person. It connects and works in my locale, but when I deploy it to Vercel, it tries to connect to the db after 10 seconds, the process is canceled because Vercel has a 10sec limit and all my APIs return 504 with this result.
MongoDB connection string is correct
MongoDB network access is open to every ip
There are Connection String in Vercel environment
Structure App Router
I connected MongoDB to the project and continued to develop in my locale, I did not use docker because I developed it as a single person. It connects and works in my locale, but when I deploy it to Vercel, it tries to connect to the db after 10 seconds, the process is canceled because Vercel has a 10sec limit and all my APIs return 504 with this result.
MongoDB connection string is correct
MongoDB network access is open to every ip
There are Connection String in Vercel environment
12 Replies
Toyger
one of the possibilities that your regions for vercel and mongo too far away
@Toyger one of the possibilities that your regions for vercel and mongo too far away
Ibizan HoundOP
10 seconds is still too long, isn't it?
@Ibizan Hound 10 seconds is still too long, isn't it?
Toyger
depends on query,
otherwise try to remove query from code and check will it work, or you can set like 1s timeout on mongodbclient
otherwise try to remove query from code and check will it work, or you can set like 1s timeout on mongodbclient
@Toyger depends on query,
otherwise try to remove query from code and check will it work, or you can set like 1s timeout on mongodbclient
Ibizan HoundOP
it's not on query, this timeout when connect to client.
@Ibizan Hound it's not on query, this timeout when connect to client.
Toyger
did you try to enable mongodb integration on vercel https://vercel.com/integrations/mongodbatlas and configure env variable
@Toyger did you try to enable mongodb integration on vercel https://vercel.com/integrations/mongodbatlas and configure env variable
Ibizan HoundOP
I integrated and I checked my env and my env works well
also works in local too
@Toyger https://www.mongodb.com/docs/atlas/reference/partner-integrations/vercel/
Ibizan HoundOP
My MongoDB network access allowed to everyone
@Ibizan Hound My MongoDB network access allowed to everyone
Toyger
still you can set mongoclient timeout to 1s and check if your function will return at least with something except vercel timeout.
Ibizan HoundOP
Solved: Changing Database 🥲
Answer