UnAuthorized Error

whenever I run my server it starts and connects with the Mongo db cluster by using this connection string

mongodb+srv://<username>:<password>@cluster0.<app_id>.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0

then whenever I run any API it gives me an unauthorized error
Request POST /createUsers failed with status code 500. MongoError: (Unauthorized) not authorized on admin to execute the command

{ insert: "User", documents: [[{username string} {email string} {password string} {userType string} {firstName string} {lastName string} {dateOfJoining string} {hotelite string} {phoneNo string} {_id ObjectID("65d7dad1733e5e3918400c38")}]], ordered: true, writeConcern: { w: 1 }, lsid: { id: {4 [63 15 80 31 82 249 70 48 178 251 59 130 9 74 226 156]} }, txnNumber: 1.000000, $clusterTime: { clusterTime: {1708644803 1}, signature: { hash: {0 [190 103 136 116 46 139 122 245 107 244 215 147 242 240 182 245 107 117 255 127]}, keyId: 7338357851812790272.000000 } }, $db: "admin" }

how to solve this issue in the cluster network access the user has Atlas admin access but still, it is not allowed to do anything

Hi @Hassan_Riaz,

You are trying to insert the data in the admin database which is one of the system collections and reserved for internal use only. Please create another database with a different name other than reserved databases. To read more, please refer to the System Collections - MongoDB Documentation.

Best regards,
Kushagra

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.