MongoDB password with “@” in it

前端 未结 16 2021
遇见更好的自我
遇见更好的自我 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

    None of the solutions mentioned above worked for me. I researched it further and found out that I had to include the useNewUrlParser parameter.

    mongoose.connect(db, {
        useNewUrlParser : true
        },
        err => {
        if (err){
            console.error('Error: ' + err)
        }
        else{
            console.log('Connected to MongoDb')
        }
    })
    

    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.

提交回复
热议问题