I'm trying to connect to a MongoDB database with a username and password using Mongoose in Node.js. All the docs say that the connection string should look like
mongodb://username:password@host:port/db
However, the password contains the '@' character in it. How can I make a connection string out of this that mongoose will understand? Can I escape the '@' in the password or is there another method of connecting I have to use?
use pwd instead pass, that worked for me for version3.2
None of the solutions mentioned above worked for me. I researched it further and found out that I had to include the useNewUrlParser parameter.
From what I understand, you need a specific version of MongoDB in order to use this. For more details, check Avoid “current URL string parser is deprecated” warning by setting useNewUrlParser to true
It is to get rid of the warning but clearly the version also affect the required parameter.
I haven't tested all special characters but it definitely works with '@#$'.
Hope this helps.
Use this syntax:
If your password has special characters:
Use the
options
parameter of themongoose.connect
call to specify the password instead of including it in the URL string: