Active Database not shown in MongoDB Compass

Dear community,
we have a database running which contains data, but it does not show up in MongoDB Compass (weirdly it sometimes shows up after restarting the database container in docker). Would anyone have an idea, why this is occuring?

As a little background: A colleague built a little image/audio presentation tool running locally, with a server, a client and a database. The tool is accessed through the browser via localhost:8080, with database at 27017. Everything is run via docker and works fine. The data is visible and useable within the tool, however the database does not show up whe I connect to it via Compass on localhost 27017, compass only shows admin, config and local. Once in a while our database, hosting the images and audio files does show up and is accessible. I however cannot explain how this came about other than restarting the containers in docker.

As a disclosure on the side, I am just the user of the tool and not very much into the IT details and quite a beginner in terms of coding :). Please let me know if any further details are needed. Thank you in advance for your advice!
P.S. The command show dbs as well only returns admin, config and local.

David

I am not too familiar with Docker, but the localhost:27917 seen by the dockerized application might not be the same localhost:27017 seen by Compass that runs on the docker host.

I imagine that the docker file indicates the host/port mapping.

You might have no mapping for MongoDB as it would be a way to completely hide the database from the world outside the application.

Dear Steeve Juneau,

thank you for your advice! I now checked the ports. As far as I understand, the port 27017/tcp has been exposed and the ports seem to have been mapped allready, if I interpret the console output correctly: .0.0.0:27017->27017/tcp, :::27017->27017/tcp

What is still weird is that in the past, without me doing anything (afaik) other than running the docker containers, I was sometimes able to see the database in MongoDB Compass.
Thanks and greetings

About:

Is that possible that you have 2 instances of mongod running?

When the docker container is running you see your databases because you are accessing the docked version. But when the container is not running you are accessing the host version which does not have the database because they are in the container version.

I am not sure if that can be done with a linux host, since you usually cannot have more than 1 process listening to the same port. But somehow, Windows seems to allow it. Only one receive connections but the other one will get them when it terminates. Or something like that.

1 Like

Thank you very much for your reply and advice.

Compass was able to find the database.
Compass did not connect and could not find anything on 27017 when docker was not running, so it seems that it has allways connected to the intended database from docker, but I am not sure.

I could not make out if I had multiple instances running, so I made a reset of everything.
I have now de- and re-installed both compass and docker and deleted all files which have been associated with the database and made everything new.

Now after this process compass connects and actually shows the database which has not been shown previously. However all the steps in running containers in docker and connecting via compass remained the same as before. Interestingly, when compass and docker were reinstalled it showed data from the old database. Is there some sort of cache to be cleared?

Compass now shows the database running inside the linux/docker host, but unfortunately I cannot figure out what has changed.