Error Message: MongoError: bad auth Authentication failed through URI string

前端 未结 15 1924
终归单人心
终归单人心 2020-12-29 02:36

I\'m trying to connect to my mongoDB server via the connection string given to me by mongo:

"mongodb+srv://david:p         


        
15条回答
  •  不知归路
    2020-12-29 03:07

    Are you writing your password in the place of ? If your aren't, a good practice is to create a environment variable on your operating system and call it using process.env.[your variable]. Ex:

    const password = process.env.YOURPASSWORDVARIABLE
    const db = 'mongodb+srv://david:'+password+'@cluster0-re3gq.mongodb.net/test?retryWrites=true'
    

    Better yet, you can also put your whole url connection string inside a env variable:

提交回复
热议问题