In this guide I will show a way to connect from MongoCompas to the internal self-hosted MongoDB database.
Making a connection to the internal MongoDB database of the self-hosted can be of great help to find bugs, for example the current SaaS integrations bug. In addition to that, support could be provided with a remote connection to users when they have a problem with this database and thus determine more quickly what is going wrong.
In order to expose the internal Mongo database of a self-hosted we will follow these steps
- Enter the command execution of the docker container where Appsmith is
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08f8110ee9c0 appsmith/appsmith-ce "/opt/appsmith/entry…" 2 hours ago Up 2 hours (healthy) 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp appsmith
$ docker exec -it c2d969adde7a bash
root@c2d969adde7a:/#
- Create a folder called Ngrok and go to that folder
mkdir ngrok
cd ngrok
- install Ngrok in the container\
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | tee /etc/apt/sources.list.d/ngrok.list && apt update && apt install ngrok
-
Get your Ngrok token for this create an account in this link and the web will give you the token
-
Bind Ngrok to your account with the following command
ngrok config add-authtoken <token>
- now expose the Mongo database port
ngrok tcp 27017
- Example how to get Ngrok host and port to make connections.
appsmith@ngrok:~$ ngrok tcp 27017
Session Status
online
Account Appsmith-svg (Plan: Free)
Version 3.1.0
Region Europe (eu)
Latency 164ms
Web Interface http://127.0.0.1:4040
Forwarding tcp://0.tcp.eu.ngrok.io:16696 -> localhost:27017
Connections
ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
- For example, the host and the port to make that connection would be.
host: 0.tcp.eu.ngrok.io
port: 16696
Next we will show how to obtain the connection credentials
- Find the folder where you have your
docker-compose
file - Go to the folder
stacks.
- Go to the
configuration
folder - Enter the
docker.env
file. - In this file look for
APPSMITH_MONGODB_USER
Note: performing this search is easier from VS code
- Once this file is found, you will see all the information necessary to connect to this Mongo database.
To connect via Mongo compass you can use this URI
- You only have to put your password and the host and port that Ngrok gave you
mongodb://appsmith:<<password>>@0.tcp.ngrok.io:19311/?authMechanism=DEFAULT&authSource=appsmith&directConnection=true