Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Can't connect to mongodb even though the url is correct.

default discord avatar
tresillo_7 months ago
8

I'm using a local instance of mongodb in dokploy. When I try to build or run the project, I get an error that mongoose couldn't connect to the db, but the ip of the db in the error is set to localhost even though the variable is setup correctly.



[18:09:59] ERROR: Error: cannot connect to MongoDB. Details: connect ECONNREFUSED ::1:27017, connect ECONNREFUSED 127.0.0.1:27017


I've tried to see if it was a problem with IP address and using

docker1.home

works and shows an error with that address, but If I use the correct address

dokploy.home

it goes back to localhost

  • default discord avatar
    nlvogel7 months ago

    This is because your local db isn’t available at build. Use experimental build mode compile:

    https://payloadcms.com/docs/production/building-without-a-db-connection#using-the-experimental-build-mode-nextjs-build-flag

    It bypasses Next’s database requirement for SSG

  • default discord avatar
    tresillo_7 months ago

    And what about running

    pnpm dev

    I'm getting the same behaivour

  • default discord avatar
    nlvogel7 months ago

    Are you trying to connect to your local Dokploy database from your local machine? As far I know, you need an external connection string to do that

  • default discord avatar
    tresillo_7 months ago

    I'm using the server ip on my local machine, it was working before I updated all packages

  • default discord avatar
    nlvogel7 months ago

    Does it work if you roll back your update?

  • default discord avatar
    tresillo_7 months ago

    I've tried downgrading all payloadcms package as lower as 3.59.0 but didn't work



    I was trying to migrate to cloudflare workers, but since mongoose isn't supported yet, I rolledback all the changes, now I'm getting this problem

  • default discord avatar
    nlvogel7 months ago

    Have you tried an external connection string from Dokploy? Just to test?

  • default discord avatar
    tresillo_7 months ago

    I've tried connecting to the db using the same string I have setup as enviroment variable and it did work using IntelIJ DataGrip, so the URI works



    It does build with this change



    But if I do

    pnpm start

    I get the db connection error



    Fixed, I was really dumb, in the replica configuration the hosts was set to

    127.0.0.1

    so it could be reached from outside. Change to the IP of the VM and not it's working back again 🤦

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.