MongoDB password with “@” in it

前端 未结 16 1943
遇见更好的自我
遇见更好的自我 2020-11-27 14:03

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

<         


        
16条回答
  •  自闭症患者
    2020-11-27 14:13

    Also, if your password contains a percentage, %, 
     Because the percent ("%") character serves as the indicator for percent-encoded octets, it must be percent-encoded as "%25" for that octet to be used as data within a URI
    
    for example, if your password is John%Doe, the new transformed password will be John%25Doe or
    If password is Paul%20Wait, New Password will be Paul%2520Wait
    
    mongoClient.connect("mongodb://username:John%25Doe@host:port/dbname", function(err, db) {
    // password is John%Doe
        }`enter code here`
    );
    

提交回复
热议问题