Skip to main content

Command Palette

Search for a command to run...

Recently faced this authentication error in mongoDB connection using docker container

Published
2 min read
Recently faced this authentication error in mongoDB connection using docker container

In my projects i do use docker containers for the db as it is heavy to have databases in locally and it will hectic in long run so why not using docker containers. Docker containers made developers job much easier by the help of virtualization. So great thanks to the Docker team.

So i was building an auth system for my application named “Mediminder” ( later on that ) and i wrote the yaml config file how it should be done and in the .env file added the mongo_uri like “mongodb://<your_db_username>:<your_db_password>@localhost:27017/<folder_name>?authsource=admin” , but using this and using a mongoose.connect() to the uri it didn’t work and returned this error as authentication failed. I had went through with this problem for more than a week trying again and again , then finally i tried to ask about it in discord servers . That’s what made different , someone told me try clean the mounted volumes and start again , i tried and boom the server respond no errors came .

And then i looked into it actually i did another project before where i used the same name for volume mounting in another compose file and that pulled me into that problem.

So make sure you never use same volume names for different containers or clear them and try again if any container fails

My socials :

linked in : www.linkedin.com/in/debanjan-das13

github : https://github.com/Debanjan2007