2 / 2
Mar 14

Hi MongoDB Community,

I’m a beginner and trying to connect to MongoDB using C#.I was connecting mongo cluster to my app which I am working on and captured the connection string form the MongoDB Compass for Desktop and used the string direct to the connection id and was encountered with the error “MongoDB.Driver.MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1
and Later on some research found that there is the Encoding Format to the password I tried to manually check the connection string everything was correct but still was on the error.
MongoDB adds an default Encoding to password within the connection string which makes the connection fail with the error and my auto-generated password was not having any special character in it.
for ex:
username: abc123 & password: pswd123
the default connection string from MongoDB Compass App is :

“mongodb+srv://abc123:%3Cpswd123%3E@[suggestionsapp.i5ww4.mongodb.net/]” Which Refuses the connection with above error.

and if you just remove the encoding from password that is %3C & %3E which make the new connection string as:
mongodb+srv://abc123:pswd123@[suggestionsapp.i5ww4.mongodb.net/]" and it resolves the error.

I am Not sure if it is safe to remove encoding from the connection string but I tried and it worked so I guessed it works here is the reference to the article.
I request the MongoDB Community to provide feedback on this feed. If I made any mistakes, please consider that I am a beginner correct me if I did something wrong.

Shivam G. Nimbalkar

1 month later

Hey @Shivam_Nimbalkar,

Welcome to the MongoDB Community Forums! Your understanding is correct that for any special characters in the password field as seen here, they should be percent encoded. It looks like the percent encoding is including the < and > characters. You don’t need to set your password in angular brackets i.e You can exclude them from your connection string unless they are actually a part of your password. Hope that helps.

Thanks,

Rishit.