MONGODB_URI=mongodb://root:password@mongodb_container:27017/evcs
payload aint working
is it supposed to be database, then port?
I just renamed my DB
in mongodb
trying to switch payload over, getting destroyed
Original connection I had was
MONGODB_URI=mongodb://root:password@mongodb_container:27017/
btw i am using mongodb_container instead of localhost
due to container stuff
is mongo running via docker-compose or something? What network mode?
Mongo is running via docker-compose
I would expect it to still be localhost if you're running locally and just hitting a DB running in docker
Yes, but I am trying to connect from another container
furthermore, if I do
MONGODB_URI=mongodb://root:password@localhost
it works
but
MONGODB_URI=mongodb://root:password@mongodb_container/evcs it does not work
I'm not very familiar with communicating container to container, and it seems outside the realm of Payload. Might need to look elsewhere to troubleshoot. Here is the docker-compose that can be used for development - that may be some help, not sure.
version: '3'
services:
payload:
image: node:18-alpine
ports:
- "3000:3000"
volumes:
- .:/home/node/app
- node_modules:/home/node/app/node_modules
working_dir: /home/node/app/
command: sh -c "yarn install && yarn dev"
depends_on:
- mongo
environment:
MONGODB_URI: mongodb://mongo:27017/payload
PORT: 3000
NODE_ENV: development
PAYLOAD_SECRET: TESTING
mongo:
image: mongo:latest
ports:
- "27017:27017"
command:
- --storageEngine=wiredTiger
volumes:
- data:/data/db
logging:
driver: none
volumes:
data:
node_modules:
Thats fine Elliot
how do I then connect to
MONGODB_URI=mongodb://root:password@localhost/evcs
?
Because I cannot connect to mongodb container even in localhsot
from my host machine
MONGODB_URI=mongodb://root:password@localhost
Works
but adding /evcs doesnt
That seems like a valid URI to me. Maybe a permissions thing? What is the error?
Will paste it soon
[03:12:09] ERROR (payload): Error: cannot connect to MongoDB. Details: Authentication failed.
Yeah, seems like your user creds don't have permission to create a new DB possibly
Hello Elliot
MongoServerError: not authorized on test to execute command { aggregate: "users", pipeline: [ { $match: {} }, { $group: { _id: 1, n: { $sum: 1 } } } ], cursor: {}, lsid: { id: UUID("49c9917e-62a5-4adf-a529-29d73271d386") }, $db: "test" }
So I have done things correctly
1. Created a new database called EVCS
2. Gave the correct user to EVCS via mongosh shell
3. Connected successfully with payload
4. But payload is still wired to target the "test" database
This is getting into MongoDB administration territory, but a quick search of that error turns up some solutions.
https://dba.stackexchange.com/questions/285345/not-authorized-on-test-to-execute-command
Custom auth db of some sort possibly
Thx it works now!
I thought it was a payload error
lmao
Glad we were able to figure it out
I had a similar issue with using a local podman container. For me, I was getting the same error, but when trying to initialize payload for the first time with
yarn dev
. The solution for me was to add
?authSource=admin
to the end of my MONGODB_URL in .env after the payload database name.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.