I've used create-payload-app to create my project and a free Atlas cluster to quickly get up and running. On first load of the admin panel I created the user and payload created a new database named test at the connection I specified. Is there a way to change that to a proper name?
Now I'm testing the deployment to a DigitalOcean droplet and installed MongoDB there, do I have to create the database myself or is payload going to create that on first build based on the schema? Is it going to choose the name "test"?
I used a string like this in the ENV when using paylod with atlas, change test to whatever else. Most likely a similar principle on digital ocean:
MONGODB_URI=mongodb+srv://user:pass@serverlessinstance00.vkge0k0.mongodb.net/test?retryWrites=true&w=majority
Is this used to specify which database name to connect? So if not specified it will create a test database? I guess I'll have to create a db with the name I want in digitalocean before building payload
yes i belive so, changing it to "staging" would create a new db for me called staging
I'm trying on the digitalocean droplet with a local mongodb installation, latest 6.07 version, in but I get:
ERROR (payload): Error: cannot connect to MongoDB. Details: Authentication failed.if I place the /dbname at the end.
This connection string works, but if I add the database name at the end it throws the authentication error
MONGODB_URI=mongodb://admin:<Your MongoDB password>@127.0.0.1:27017
Connecting without the database name option it created the test database like it did in local. Why is this thing not mentioned in the Payload docs?
I even tried changing the string to /test?retryWrites=true&w=majority but it's giving the same error with test db as well, seems like it's only working without the database name specified and connects to the standard it created by itself
Could that be something related to the PAYLOAD_SECRET ? I've just copied the same I have on the frontend where my db name is "test"
is the db created? If not, does the user you use have access to create databases?
Yes I created the db before running payload, but I did that with MongoDB Compass, because I also imported a few collections to test data. Could that be the reason?
Does the db needs to be created by the same user running payload? The mongodb string with admin:pass should give admin access to all databases, so why I can't specify which one?
That can't be it, because I also tried changing the string to /test and still didn't connect to the test db that payload itself created
At least they could have called it "payload" instead of test, just to make it clear. "test" db in production doesn't look good
Hmm. Should work with the db at the end. It’s standard mongodb connection uri. 🤔
I did some more testing, on local with a mongodb atlas the /dbname at the end works and I just imported everything into a new database name. On the droplet, if give it the atlas db URI it works with the /bdnamem, but when I use the local mongodb it gives the error:
ERROR (payload): Error: cannot connect to MongoDB. Details: Authentication failed.
I tried with
mongodb+srv:
but it says URI cannot have port number. If I remove the port number:
ERROR (payload): Error: cannot connect to MongoDB. Details: querySrv ENOTFOUND _mongodb._tcp.127.0.0.1
It has to be an issue with the local installation of MongoDB on the droplet, but why is it not working with /test if that's the database payload itself created ??
SOLVED:
I found example in the docs:
For a standalone that enforces access control:
mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin
the end
?authSource=admin
after the /dbname fixed it
nice 🙂 good find
Star
Discord
online
Get dedicated engineering support directly from the Payload team.