Heroku mongodb deployment error React course

I get an error when trying to connect heroku to mongodb atlas. In the logs, I do see a message on connection to db being successful but the following error happens:
MongoError: (Unauthorized) not authorized on admin to execute command { listIndexes: “users”, cursor: { }, $clusterTime: { clusterTime: {1603819118 3}, signature: …

It appears this was posted once in the forum but it can no longer be found. Any help to fix this would be greatly appreciated.

Thanks,
Roshin

It seems you use node.js 3.0 version, use node.js 2.2.12
heroku cannot understand “srv+mongodb://…" use “mongodb://…” instead

4 Likes

Dear Hakuhal,

Thank you for your reply. It worked, I can connect and I see no errors! I was afraid if M0 free cluster limitations were the problem but that does not appear to be the case.

Really appreciate it,

Roshin

I am glad it helped :blush:

help me i am facing unpredictable error
Setting vidly_db and restarting ⬢ peaceful-cove-18303… done, v20
vidly_db: mongodb+srv://kukab:kokabsaqib40@vidly.gtszv.mongodb.net/vidly?retryWrites=true
‘w’ is not recognized as an internal or external command,
operable program or batch file.
when I do heroku open

getting this error
2020-11-23T20:32:38.091832+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=peaceful-cove-18303.herokuapp.com request_id=4954b87a-b9c1-4ce3-a330-36255bb8256a fwd=“175.107.225.94” dyno=web.1 connect=5000ms service= status=503 bytes= protocol=https

do not use the “mongodb+srv://”, use the “mongodb://” options.

Hey, Thanks for your answer.

It helped me solve Unauthorized error. However, after following the steps I got this error.

‘MongoError: seed list contains no mongos proxies, replicaset connections requires the parameter replicaSet to be supplied in the URI or options object, mongodb://server:port/db?replicaSet=name’

Help would be appreciated.

My connection uri: mongodb://vidlyuser:@vidlydb-shard-00-00.wft4x.mongodb.net:27017,vidlydb-shard-00-01.wft4x.mongodb.net:27017,vidlydb-shard-00-02.wft4x.mongodb.net:27017/?ssl=true&replicaSet=atlas-13gtrm-shard-0&authSource=admin&retryWrites=true&w=majority

@sampreeth : I got the same error message. For me, using the Heroku CLI was removing characters after any ampersand claiming it is some command. Putting it in double quotes worked for small strings, but not large ones?!

ANYWAY, I used the Heroku dashboard (https://dashboard.heroku.com/apps/ --> “Settings” button --> “Reveal Config Vars” button) to put the mongodb (the 2.2.12 connect version) string in for the “vidly_db” key with the appropriate changes (like password and database name).

I hope this fixes it for you.

How about authSource should I change that from admin to dbname?

@Ari87 I tried changing as mention.
Now I’m getting.
MongoError: Authentication failed. at NessageStream.messageHandler

However, my dbname is correct, password is the user password.

I’m stuck with this issue from 2 days. If you can help it would be really great.
Thanks in advance.

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.

14 Likes

thank you man!! the first time I put Heroku open it take me to the server with no errors, then I try again and send me again application error why is that? Also, do I need to connect with that url the mongoDB desktop app?

Thank you @sampreeth your solution helped

1 Like

Thanks @sampreeth your solution saved me from hours of heartache

1 Like

Hi sorry to disturb you but can you help solve this axios error
eperm: saying operation not permitted, read.
Please i will be very much grateful thanks.
Thanks

great @sampreeth brother for this tips work to me.i was struggle past 3 days but this time resolve this error.again thanks in advance. :slightly_smiling_face:

2 Likes

Thank You!
it is helpfull!!

1 Like

Thank you! :slight_smile: you are great

1 Like

Hello Justly,
sorry for the late reply, I hope your error has been resolved.

Thanks, guys for this helpful discussion for many of us, I appreciate that! :+1: