Heroku mongodb deployment error React course

Steps I followed to fix this issue.

First,

npm update mongoose

Latest mongoose as of 5/01/2021 is mongoose 5.11.10. If there is a newer version please check the documentation.

Second,
If you are following mosh course. Open db.js in startup folder.

Change

mongoose.connect(db)

to

mongoose.connect(db, {useNewUrlParser:true, useUnifiedTopology: true})

Three,
copy the connection string for Node driver version 2.2.12 or later.

make sure the connection string does not have (mongodb+srv)

copied connection string for node driver version 2.2.12 will look like as shown below.

mongodb://<username>:<password>@vidlycluster-shard-00-00.knv7y.mongodb.net:27017,vidlycluster-shard-00-01.knv7y.mongodb.net:27017,vidlycluster-shard-00-02.knv7y.mongodb.net:27017/<dbname>?ssl=true&replicaSet=atlas-8ezfa5-shard-0&authSource=admin&retryWrites=true&w=majority

Replace “password” with the password for the “username” user. Replace “dbname” with the name of the database that connections will use by default.
Once replaced, remove all the angle brackets.

Four,
Head over to heroku dashboad,
→Settings → Click on “Reveal Config Vars” → Enter the Key as vidly_db, value will the connection mongodb connection string.

Five,
Back to terminal,
git add .
git commit -m “Commit message”
git push heroku master
heroku open

Hope this helps someone. It was a struggle for me to find this solution.

Cheers.

Ps: @Mosh Mlab is now bought by mongodb atlas. If you could update this in your course it would be really grateful.

13 Likes