I was running mongodb with wsl2 and docker, so I needed just to add "from uri", and set up ip_adress with the ip from wsl2.
Explanation:
- Uri: This connection string is the way we can talk to robo 3t understand how to connect with our mongodb server.
- ip_address: Because of docker creates containers that are similar to servers, each container has an ip_adress, so to have access to this mongodb server, we need to find the ip_adress from the container that we need.
I used this URI:
mongodb://{username}:{password}@{ip_address}:{port}/?authSource=admin
username = MONGO_INITDB_ROOT_USERNAME
password = MONGO_INITDB_ROOT_PASSWORD
port = 27017(docker container port will be set up on docker parameter "-p")
ip_address = Ip from wsl2 in my case, or localhost if you running docker locally.
This was my command to run the container on the first time :
docker container run -d -e MONGO_INITDB_ROOT_USERNAME=mongouser -e MONGO_INITDB_ROOT_PASSWORD=mongopwd -p 27017:27017 -v mongo_vol:/data/db mongo:4.4.3