MongoDB password with "@" in it


Question

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?

1
71
1/24/2013 11:20:39 AM

Use this syntax, don't forget the uri_decode_auth option.

mongoClient.connect("mongodb://username:p%40ssword@host:port/dbname", { 
    uri_decode_auth: true 
    }, function(err, db) {

    }
);
85
4/5/2017 3:05:34 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon