2

I can't seem to find a solution to this issue, I have a database on mlab I should access with a password containing a backslash \ character.

I've tried using some of the suggestions in this thread, basically encoding manually the password or using an encoding function, but authentification fails nonetheless.

Assuming my password is password\ Here's what I've noted: if my connection URL is :

  • mongodb://username:password\@dsXXXXXX.mlab.com:YYYYY/my_db I obviously have an issue with the escape character as with any javascript string,
  • mongodb://username:password\\@dsXXXXXX.mlab.com:YYYYY/my_db returns an error Error: Password contains an illegal unescaped character,
  • mongodb://username:${encodeURIComponent("password\\")}@dsXXXXXX.mlab.com:YYYYY/my_db I get Error: Password contains an illegal unescaped character along with the options [uri_decode_auth] is not supported mongoose (because I am trying to decode in mongoose.connect as such:

    mongoose.connect(config.database, { //config.database contains the URL above
      uri_decode_auth: true 
    }, function(err, db) {}
    );
    
  • mongodb://username:Simplifide35%5C@dsXXXXXX.mlab.com:YYYYY/my_db by using this website returns MongoError: Authentication failed.

  • Connecting with options like so:

    mongoose.connect("mongodb://@dsXXXXXX.mlab.com:YYYYY/my_db",
         {user: 'username', pass: "password\\"}, ()=>{});
    

    does not work either with the encoded password%5C nor password\.

What are my options aside from changing the password? What am I missing?

Thanks.

Akheloes
  • 1,352
  • 3
  • 11
  • 28
  • You might want to update that link to the "question/answer" ( not a thread ) you believe you tried solutions from, otherwise you're likely to be marked in duplicate of the same thing. The "link" you put in your question is broken and just points to `/thread`. There are other places to put the password than in the URI, and I'm certain this is already covered in an answer. – Neil Lunn Jun 11 '18 at 09:01
  • Oupsi, sorry fixed, thanks! – Akheloes Jun 11 '18 at 09:03
  • So I just looked, and there is in fact answers that tell you to put the password in the "options" block. See [`MongoClient`](http://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html) in the node driver API documentation. Anything in "options" is perfectly valid in the exact same place connecting with mongoose. `{ auth: { user, password } }` – Neil Lunn Jun 11 '18 at 09:03
  • Tried it as well, does not work for me, let me edit the question to make that clear. – Akheloes Jun 11 '18 at 09:10
  • Could not have tried very hard, because guess what I just did in the last five minutes. Works fine for me, so I suggest you actually use it. – Neil Lunn Jun 11 '18 at 09:11
  • I thought you were mentioning the user/password options, that one I actually have not tried still. – Akheloes Jun 11 '18 at 09:15
  • `mongoose.connect("mongodb://@dsXXXXX.mlab.com:YYYYY/my_db", { auth: { user: 'username', password: "password\\" } }, ()=>{});` pardon the question, but is it supposed to be used? – Akheloes Jun 11 '18 at 09:21
  • If course it supposed to be used. In fact it's exactly how you avoid problems by instead passing things into the `"options"` instead of attempting to construct in the URI. I have never ( in production ) passed anything more than the "base" connection details in the URI itself. These days with `mongodb+srv` it's a really short URI, and even the other replica set settings from DNS. But authentication and other things, all in the "options". – Neil Lunn Jun 11 '18 at 09:27
  • Alright, this will sound dumb: a collegue of mine has changed the password without alerting me... should I erase the question? – Akheloes Jun 11 '18 at 09:33
  • You can do something like that https://stackoverflow.com/questions/50590080/unhandled-promise-rejection-error-url-malformed-cannot-be-parsed/50590439#50590439 – Ashh Jun 11 '18 at 13:37
  • Yes, that's actually what I tried and it worked fine, thanks! – Akheloes Jun 11 '18 at 13:41

0 Answers0