Struggling to set up Payload CMS. When running npm run dev
, I encountered an error stating:
ERROR (payload): Error: cannot connect to MongoDB. Details: URI does not have hostname, domain name and tld [nodemon] app crashed - waiting for file changes before starting...
I installed Mongo locally on my machine, choosing the option to run it as a Network Service User and skipping Mongo Compass installation. During Payload's setup, I provided the path to the Mongo database. After creating a new database in Mongo, I selected the "connect to your app" option and copied this snippet:
mongodb+srv://my_db_name:@my_name.something.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
I pasted this snippet where Payload requested it. In my project, there is a .env
file which looks like this:
MONGODB_URI = mongodb+srv://my_db_name:my_password@my_name.something.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
PAYLOAD_SECRET = my_super_long_secret_key_thats_not_this
Although I added quotes around the values thinking it might be necessary, I still got the same error. The URI in the .env
file contains all required information according to the docs. Following the instruction in the documentation, I tried running node server.js
, or in my case server.ts
since I'm using TypeScript, but it did not solve the issue. Watching a video tutorial by the creator, I noticed they used yarn dev
, so I attempted npm run dev
to start the server successfully until the Mongo connection failed. Any ideas on what could be going wrong?