MongoServerError: (Unauthorized)

Hey folks,

Hope everyone is doing well :slight_smile:

Could you pls help? I’m not sure how to solve this issue. I’ve already checked the roles and they look fine :slight_smile:

Thank you :slight_smile:

CLI logs:

organic 	SCRAM 	
atlasAdmin@admin
dbAdmin@*
All Resources
show dbs
appsmith    4.00 KiB
admin     280.00 KiB
local       1.94 GiB

Atlas atlas-rpzlrl-shard-0 [primary] organic> use appsmith
switched to db appsmith
Atlas atlas-rpzlrl-shard-0 [primary] organic> rs.initiate()
MongoServerError: (Unauthorized) not authorized on admin to execute command { replSetInitiate: {  }, apiVersion: "1", lsid: { id: {4 [186 179 92 153 213 51 75 239 132 55 145 35 115 149 12 163]} }, $clusterTime: { clusterTime: {1686379830 1}, signature: { hash: {0 [21 155 210 75 223 46 113 58 228 58 71 104 20 204 211 110 125 65 36 124]}, keyId: 7200415790166704128.000000 } }, $db: "admin" }

Atlas atlas-rpzlrl-shard-0 [primary] organic> show users
MongoServerError: (Unauthorized) not authorized on admin to execute command { usersInfo: 1, apiVersion: "1", lsid: { id: {4 [186 179 92 153 213 51 75 239 132 55 145 35 115 149 12 163]} }, $clusterTime: { clusterTime: {1686379830 1}, signature: { hash: {0 [21 155 210 75 223 46 113 58 228 58 71 104 20 204 211 110 125 65 36 124]}, keyId: 7200415790166704128.000000 } }, $db: "organic" }

As which user you logged
Did you login by authenticating against admin db?
DbAdmin can do administrative tasks but cannot query db
I think you need read privs on admin db

1 Like

Thanks so much for your reply, mate :slight_smile:

I’m logged as organic into Appsmith db:

mongosh "mongodb+srv://cluster0.tkwb4.mongodb.net/appsmith" --apiVersion 1 --username organic

Enter password: ***************
Current Mongosh Log ID:	64844fb4e5ab65e6b408a2e4
Connecting to:		mongodb+srv://<credentials>@cluster0.tkwb4.mongodb.net/appsmith?appName=mongosh+1.9.1
Using MongoDB:		6.0.6 (API Version 1)
Using Mongosh:		1.9.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

Atlas atlas-rpzlrl-shard-0 [primary] appsmith> show users
MongoServerError: (Unauthorized) not authorized on admin to execute command { usersInfo: 1, apiVersion: "1", lsid: { id: {4 [253 203 135 27 140 176 74 183 144 213 91 135 241 226 63 42]} }, $clusterTime: { clusterTime: {1686392773 3}, signature: { hash: {0 [95 129 127 104 101 25 113 177 86 68 70 78 82 114 251 149 186 154 159 35]}, keyId: 7200415790166704128.000000 } }, $db: "appsmith" }

Atlas atlas-rpzlrl-shard-0 [primary] appsmith> db.getUser("organic")
{
  _id: 'admin.organic',
  user: 'organic',
  db: 'admin',
  roles: [ { role: 'atlasAdmin', db: 'admin' }, { role: 'dbAdmin', db: '*' } ]
}

Atlas atlas-rpzlrl-shard-0 [primary] appsmith> db.getUser("admin")
MongoServerError: (Unauthorized) not authorized on admin to execute command { usersInfo: { user: "admin", db: "appsmith" }, apiVersion: "1", lsid: { id: {4 [253 203 135 27 140 176 74 183 144 213 91 135 241 226 63 42]} }, $clusterTime: { clusterTime: {1686392773 3}, signature: { hash: {0 [95 129 127 104 101 25 113 177 86 68 70 78 82 114 251 149 186 154 159 35]}, keyId: 7200415790166704128.000000 } }, $db: "appsmith" }
Atlas atlas-rpzlrl-shard-0 [primary] appsmith> show users
MongoServerError: (Unauthorized) not authorized on admin to execute command { usersInfo: 1, apiVersion: "1", lsid: { id: {4 [253 203 135 27 140 176 74 183 144 213 91 135 241 226 63 42]} }, $clusterTime: { clusterTime: {1686392773 3}, signature: { hash: {0 [95 129 127 104 101 25 113 177 86 68 70 78 82 114 251 149 186 154 159 35]}, keyId: 7200415790166704128.000000 } }, $db: "appsmith" }
Atlas atlas-rpzlrl-shard-0 [primary] appsmith> use admin
switched to db admin
Atlas atlas-rpzlrl-shard-0 [primary] admin> db.getUser("admin")
MongoServerError: (Unauthorized) not authorized on admin to execute command { usersInfo: { user: "admin", db: "admin" }, apiVersion: "1", lsid: { id: {4 [14 77 209 98 125 34 75 140 146 152 131 103 17 117 8 171]} }, $clusterTime: { clusterTime: {1686393103 5}, signature: { hash: {0 [185 49 198 18 71 120 232 137 174 111 13 147 161 63 212 7 72 103 183 162]}, keyId: 7200415790166704128.000000 } }, $db: "admin" }
Atlas atlas-rpzlrl-shard-0 [primary] admin>

Hi @Tarlan_Isaev ,
You need to authenticate on admin database and not on appsmith db, so you need to correct your connection string!

BR

1 Like

Hi Fabio,

Thanks so much, mate :slight_smile:
Still the same :slight_smile:

mongosh "mongodb+srv://cluster0.tkwb4.mongodb.net/admin" --apiVersion 1 --username organic
Enter password: ***************
Current Mongosh Log ID:	6484a34a70ba66ec31b6045c
Connecting to:		mongodb+srv://<credentials>@cluster0.tkwb4.mongodb.net/admin?appName=mongosh+1.9.1
Using MongoDB:		6.0.6 (API Version 1)
Using Mongosh:		1.9.1

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

Atlas atlas-rpzlrl-shard-0 [primary] admin> use admin
already on db admin

Atlas atlas-rpzlrl-shard-0 [primary] admin> rs.initiate()
MongoServerError: (Unauthorized) not authorized on admin to execute command { replSetInitiate: {  }, apiVersion: "1", lsid: { id: {4 [31 28 154 162 113 189 69 25 151 245 10 63 140 9 112 161]} }, $clusterTime: { clusterTime: {1686414185 3}, signature: { hash: {0 [117 147 23 148 52 226 223 49 99 69 212 50 169 110 168 73 195 67 245 170]}, keyId: 7200415790166704128.000000 } }, $db: "admin" }

Hi @Tarlan_Isaev,
Are you able now to show DBS?
I don’ t understand why you’re trying to iniziate a replica set in MongoDB Atlas.
You’re using a free tier on atlas (M0)?

BR

1 Like

Hey @Fabio_Ramohitaj,

Yeah, there’s no issue with that :slight_smile:

Atlas atlas-rpzlrl-shard-0 [primary] admin> show dbs;
appsmith    4.00 KiB
admin     280.00 KiB
local       1.94 GiB

Ohh apologies, I didn’t realise before that the replica set requires a pay tier. Have to turn it on for Appsmith to use it. Yeah, currently on the free tier :slight_smile:

Thank you :slight_smile:

Hi @Tarlan_Isaev,
So i think you can flag the solution :nerd_face:

BR

1 Like

Hey @Fabio_Ramohitaj,

Yeah. Thanks for all your help and assistance guys :slight_smile:

Kind regards.