I have created free cluster and db on Mongo Atlas but I try to connect my app by 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} }} } …
2 Likes
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
2 Likes
God bless you. *Tears of joy :_ ))
hello, I am getting same kind of error like:
(Unauthorized) not authorized on admin to execute command { create: “sample”, capped: true, size: 5242880, writeConcern: { w: “majority” }, lsid: { id: {4 [133 92 127 66 175 140 79 35 174 118 57 40 59 137 39 110]} }, $clusterTime: { clusterTime: {1678037479 5}, signature: { hash: {0 [235 83 26 247 241 208 26 217 203 154 205 184 108 184 228 33 93 229 204 81]}, keyId: 7153350679543676928.000000 } }, $db: “admin” }
i tried multi[ple ways for creating collection in db. This error i got is when i got connected to mongodb compass and tried to build a connection in db.
There are 3 radio buttons available with that, but cant choose which one to choose.
Please help me out.
I think you are trying to create your collection in admin db
Connect to test db and try
Also share your compass connect string after hiding sensitive information like password,cluster address
2 Likes
hi
I use your method to get connect string. But what it gives me is mongodb://zmz2:123@ac-64yh6ax-shard-00-00.pbddalw.mongodb.net:27017
mongoose
.connect(MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
this will help you , pass this object
2 Likes
This is because Admin db is used for administrative tasks not for storing the data. Try creating a new db and use it
1 Like