(Unauthorized) not authorized on admin to execute command

I have created free cluster and db on Mongo Atlas but I try to connect my app by :slight_smile: mongoose.connect(‘mongodb+srv://Ahmed:Admin123@st.0qt0i.mongodb.net/bktrans?retryWrites=true&w=majority’)

And the below error appears when I run rpm start on my API:

(Unauthorized)not authorized on admin to execute command {listIndexes: “consumers“, cursor:{ }, $clusterTime: { clusterTime: {1634734692 10}, signature: { hash: {203 165 207 4 203 170 4 127 37 213 33 4 100 167 170 44 201 49 111 36} }} } …

Hi Ahmed ,

I got this error recently while connecting from a node app on Heroku to MongoDB Atlas - I had issue with connection string .

I tried using below the below format - and it worked.

mongodb://:@-cluster0-shard-00-00.scxjr.mongodb.net:27017,-cluster0-shard-00-01.scxjr.mongodb.net:27017,-cluster0-shard-00-02.scxjr.mongodb.net:27017/?ssl=true&replicaSet=atlas--shard-0&authSource=admin&retryWrites=true&w=majority

It worked.

I got this from MongoDB Atlas tab → Deployment side bar → Databases → on right Connect button inside . Connect to your application section → Select Driver - Node.js and Version 2.2.12 or later - below it will show the example connection string.

Please let me know if this solved your issue