FailedToParse: Password must be URL Encoded for mongodb
Asked Answered
M

2

9

I am trying to connect to MongoDB v4.2.X using below command and getting the error.

FailedToParse: Password must be URL Encoded for mongodb:// URL: mongodb://user:user@123@localhost:27017/my-employees?authSource=admin try 'mongo --help' for more information

The URL = mongodb://user:user@123@localhost:27017/my-employees?authSource=admin

Miniver answered 15/5, 2020 at 16:49 Comment(2)
I think you are writing it in a wrong way. Try this way: mongodb+srv://user:password@localhost:27017/my-employees?authSource=admin Lindie
Hey, still the same error.Miniver
M
19

If your password is user@123, you're using a special character (a delimeter) in your connection URI. According to the docs:

If the username or password includes the at sign @, colon :, slash /, or the percent sign % character, use percent encoding.

Percent encoding is another name for URL encoding mentioned in your error.

@ will be %40 in percent-encoding, and your connection string would be:

mongodb://user:user%40123@localhost:27017/my-employees?authSource=admin

You can also use this online tool to URL-encode your username/password.

Mustard answered 15/5, 2020 at 20:53 Comment(1)
Instead of using an online tool for DB passwords, feels a little safer to just open up a node session (type node) in my terminal and use encodeURIComponent("user@123") directly, locally (assuming you have node installed)Acinaciform
K
0

According to the documentation, If the username or password includes the following characters: -

$ : / ? # [ ] @

Those characters must be converted using percent encoding.

You can encode your special character string here.

enter image description here

Katey answered 27/8 at 14:43 Comment(1)
This duplicates the accepted answer.Ganger

© 2022 - 2024 — McMap. All rights reserved.