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.

Cannot connect to MongoDB error when attempting local development

default discord avatar
brandnholl4 months ago
6

I'm currently attempting to run the "website" template locally for development. I've followed all the steps in the repo's readme but continuously get this error when running

yarn dev

in the terminal no matter what I try.

  • default discord avatar
    exo37182 years ago

    You seem to not have a local mongodb running, there are a few ways to sort this out:



    The website template comes with a docker compose file, the easiest way to get started is by running

    docker compose up -d

    from the project root.



    Alternatively you can start a local mongodb separately, either native on your system or in a docker container with port 27017 exposed, just make sure the credentials match then.

  • default discord avatar
    flatcappedlast year

    Leaving this here in case anyone else needs it. In my case changing my connection string from "mongodb://localhost:27017" to "mongodb://0.0.0.0:27017" did the trick.

  • ⬆️ this is a node v18 thing



    if runnning node 18+ you have to use

    127.0.0.0

    in place of

    localhost

    Can you connect to mongodb with Compass?

    https://www.mongodb.com/products/tools/compass

    I would ensure your variables names are correct

  • default discord avatar
    lokeshpathrabelast year

    I am stuck at the same place but none of the above worked for me. Can someone suggest what else can be done here.


    I am node 18.19.0.



    Yes I am able to connect to compass at

    http://127.0.0.1:27017
  • default discord avatar
    lando_rozaylast year

    I am stuck at a similar place. I have a Payload instance running on an Ubuntu server, where everything works fine (both in development and production mode). However, I want to be able to access my database from my local machine when I want to edit the code base, but I can't, getting "Error: cannot connect to MongoDB. Details: connect ETIMEDOUT 2a00:d0c0:200:0:ccd:dff:fec0:d062:44500".



    The connection string is correct since I can access it through mongoDB Compass on my machine.



    Anybody can help me here?

  • default discord avatar
    ianwanjira5 months ago

    Hi guys, I'm stuck with the same MongoDB connection error. I have set my database_uri to the Mongo connection string provided by Payload Cloud since I used their e-commerce template. However, every time I run the command

    yarn dev

    , I always get the MongoDB connection error. Can anybody help me out with this?

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.