Not authorized to execute command in Mongo

I have been trouble connecting to mongoDB.
In section 9 of the deployment section I am having the following issue.

After setting the vidly_db environment variable to :

mongodb+srv://vidlyadmin:1234@vidly.krcgp.mongodb.net/test

I cannot access the backend and the following error gets logged :

‘MongoError: (Unauthorized) not authorized on admin to execute command { listIndexes: “users”, cursor: { }, $clusterTime: { clusterTime: {1633210617 2}, signature: { hash: {0 [255 101 10 186 169 111 2 105 228 46 203 105 157 143 5 246 108 197 191 19]}, keyId: 6959643728893968384.000000 } }, lsid: { id: {4 [215 235 152 123 207 119 64 14 162 245 245 221 186 212 50 96]} } }’,
2021-10-02T21:37:00.910789+00:00 app[web.1]: ’ at queryCallback (/app/node_modules/mongodb-core/lib/cursor.js:223:25)’,
2021-10-02T21:37:00.910790+00:00 app[web.1]: ’ at /app/node_modules/mongodb-core/lib/connection/pool.js:541:18’,
2021-10-02T21:37:00.910790+00:00 app[web.1]: ’ at processTicksAndRejections (internal/process/task_queues.js:77:11)’

In other places it was suggested to omit the +srv from the URL as such

mongodb://vidlyadmin:1234@vidly.krcgp.mongodb.net/test

But that also logs an error for me.

My dependencies are

“dependencies”: {
“bcrypt”: “^5.0.1”,
“config”: “^1.29.4”,
“cors”: “^2.8.4”,
“express”: “^4.16.2”,
“express-async-errors”: “^2.1.0”,
“fawn”: “^2.1.5”,
“joi”: “^13.4.0”,
“joi-objectid”: “^2.0.0”,
“jsonwebtoken”: “^8.1.1”,
“lodash”: “^4.17.10”,
“moment”: “^2.20.1”,
“mongoose”: “^5.0.2”,
“winston”: “^2.4.0”,
“winston-mongodb”: “^3.0.0”
}

Any help is much appreciated!

1 Like