using special characters in mongodb password string

7,512 views
Skip to first unread message

Vishesh Singhal

unread,
Feb 6, 2016, 4:09:37 AM2/6/16
to mongodb-user
Hi,

I am using a mongodb connection string having username and password. But my password contains '&' symbol in it 

"mongodb://username:pa&ssword@server1,server2,server3/dbtest?authSource=admin&replicaSet=rsTest&connectTimeoutMS=5000"

How can I use it?

Regards,
Vishesh

Wan Bachtiar

unread,
Feb 7, 2016, 11:26:34 PM2/7/16
to mongodb-user

Hi Vishesh,

A MongoDB connection string is a URI. You can escape special characters using standard URI escape mechanism.

If your password contain a & you could encode it as %26. For example in NodeJS you could do:

MongoClient.connect("mongodb://user:pas%26word@localhost:27017/databaseName?authSource=databaseName&authMechanism=SCRAM-SHA-1", function(err, db)
    { if (err) throw err;
      else console.log(db);
    }
);

Also see Percent-encoding for more info.


If you are still having this issue, could you provide:

  • MongoDB version
  • Programming language and driver version you are attempting this from.

Regards,

Wan.

Vishesh Singhal

unread,
Feb 8, 2016, 1:41:39 AM2/8/16
to mongodb-user
Thanks Wan, I'll try using as per your suggestion and will let you know the result.
FYI, I just upgraded the mongodb from 2.4.9 to 2.6.11 and we are using C# driver 1.11 

Regards,
Vishesh
Reply all
Reply to author
Forward
0 new messages