Unable to View Data in MongoDB Compass Despite Successful Queries via Flask App

Hello MongoDB Community,

I’m facing an issue where data that I’m able to query and retrieve through a Flask application is not visible in MongoDB Compass. My setup includes a Flask application and MongoDB running in separate Docker containers, with the database data stored in a Docker volume.

Here’s the issue in detail:

  • I can successfully register a user via a POST request to my Flask app’s /register endpoint.
  • I can retrieve this user using a curl command to the Flask app’s /users GET endpoint.
  • The curl command returns the expected user data, indicating that the Flask app is able to interact with the MongoDB database correctly.
  • However, when I connect to MongoDB using Compass with the URI mongodb://localhost:27017/, the userdb database does not appear in the list of databases, nor do I see any collections or documents.

Relevant details of my setup:

  • Docker Compose is used to orchestrate the containers.
  • MongoDB is using the official mongo:latest image.
  • The docker-compose.yml file specifies the mongodb_data volume mapped to /data/db.
  • Flask connects to MongoDB using the MongoClient with the URI mongodb://mongo:27017/.

Here’s what I’ve checked so far:

  • The MongoDB service in Docker Compose is running without errors.
  • There are no filters set in MongoDB Compass that would hide the database.
  • I have refreshed and restarted MongoDB Compass several times.
  • The Docker volume appears to be correctly mapped and persisting data.

I’m puzzled as to why MongoDB Compass does not show the userdb database or its collections, while the data is clearly present and accessible to my Flask app. Has anyone encountered a similar issue, or could you provide guidance on what might be going wrong?

Any insights or suggestions would be greatly appreciated!

Is this container’s port published/exposed? Is there another container that is publishing/exposing port 27017 or a local mongod running?

Try running db.serverStatus().host on both compass and a mongosh in the container and see if they differ.

I am facing the same issue with my project as well, It is built using FastAPI server.
I am sending the data to the MongoDB and also retrieving it successfully but the data is not visible either in MongoDB Compass as well as the atlas .