Vy Do
Vy Do

Reputation: 52666

How to connect MongoDB docker by Studio 3T?

I am using docker image https://hub.docker.com/_/mongo/ (Latest MongoDB version)

I run command

docker run --name some-mongo -d mongo

Then I install Studio 3T I enter connection information like this

enter image description here

but I can't connect. What is correct connection must declare in Studio 3T in this case? How to connect MongoDB instance (docker) by Studio 3T?

Upvotes: 10

Views: 10934

Answers (6)

mathems32
mathems32

Reputation: 365

I had a problem connecting Studio 3T with MongoDB earlier this week, and it consumed my entire working day, so I gave up on using Studio 3T to ensure time for other things and an alternative. Today I found this short video tutorial by Studio 3T on how to connect Studio 3T with MongoDB. Following the directions, I was surprised that a connection was made successfully.

I recommend you watch/follow this video: https://www.youtube.com/watch?v=_Ka3-HGNlYE

If it helps you, remember to tick this answer.

Upvotes: 0

Gabriel Silva
Gabriel Silva

Reputation: 73

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:

  1. Uri: This connection string is the way we can talk to robo 3t understand how to connect with our mongodb server.
  2. 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

Upvotes: 1

Nelson Bwogora
Nelson Bwogora

Reputation: 2389

for those on windows kindly check in task manager and make sure you don't have a local installation of mongo db server running then use localhost in address/connection string

Upvotes: 0

Lone Ronin
Lone Ronin

Reputation: 2910

  • Click New Connection

  • Enter the Connection name

  • Click on From URI

  • Enter the URI in the following format mongodb://{username}:{password}@{ip_address}:{port}/?authSource=admin

  • Click OK

  • Click Test Connection

  • Works?

    • No: Check your username, password, etc
    • yes: Congrats!

Upvotes: 7

yamenk
yamenk

Reputation: 51886

You need to find the IP address where the Docker container is running. On Mac docker runs in the background inside a linux VM that has its own IP. Thus localhost will not work.

To find the IP, run docker-machine env default and set this IP in the Server field.

Upvotes: 1

Rick Rongen
Rick Rongen

Reputation: 739

You need to export the port you want to use in your docker command. e.g.

docker run -p 127.0.0.1:27017:27017 --name some-mongo -d mongo

This opens the port of the container on your host machine.

Upvotes: 12

Related Questions