mongodbmongodb-compass

MongoDb Compass: Not able to connect using standard connection string


I have a mongodb hosted on an EC2 instance. The securirty group allows port 27017 and in mongo.conf, the port binding is set to 0.0.0.0. I am able to connect to this mongo instance using the mongo CLI on my machine, so it means the server is accessable and port/ip binding is not the problem. But, I can connect using my MongoDb Compass application. It gives me this error:

Authentication failed.

This is what my connection string looks like:

mongodb://myuser:mypwd@my-ec2-ip:27017/myDatabase

This is the same connection string I use to connect via the mongo CLI on my machine:

mongo "mongodb://myuser:mypwd@my-ec2-ip:27017/myDatabase" and this works. What am I doing wrong?


Solution

  • Turns out compass was not picking up the authentication database from my connection string: mongodb://myuser:mypwd@my-ec2-ip:27017/myDatabase. myDatabase was the database I was trying to connect, but compass was trying to authenticate me against the default admin database. So in the "Fill in connection fields individually" section, I set the "Authentication Database" to myDatabase manually and it worked.