0

I have installed mongo db server and created an admin user :

use admin
db.createUser(
  {
   user: "superAdmin",
   pwd: "admin123",
   roles: [ "readWrite"]
  })

Then I reconnect the shell using :

mongo --port 27017 -u "superAdmin" -p "admin123" --authenticationDatabase "admin"

However it's still allowing me to query database without even providing credentils.

enter image description here

Moreover, when I connect using credentials it's saying: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted.

What should I do to prevent anonymous connection and how can I get rid of this access control not enabled thing?

  • Please confirm you did the next steps https://docs.mongodb.com/manual/tutorial/enable-authentication/#re-start-the-mongodb-instance-with-access-control after creating admin user – Alex Blex Jun 21 '21 at 09:17
  • Yes, I followed all of it. – Faizan Saeed Jun 21 '21 at 09:19
  • 1
    The error message says the opposite. The "access control is not enabled" means you did not restart mongod with auth enabled – Alex Blex Jun 21 '21 at 09:23
  • Does this answer your question? [MongoDB: Server has startup warnings ''Access control is not enabled for the database''](https://stackoverflow.com/questions/41615574/mongodb-server-has-startup-warnings-access-control-is-not-enabled-for-the-dat) – Sohan Jun 21 '21 at 09:44
  • @AlexBlex > I started mongod using mongod --auth --port 27017 --dbpath /var/lib/mongodb and then I entered the follwoing command: mongo --port 27017 -u "superAdmin" --authenticationDatabase "admin" -p But it's still saying "access control is not enabled." – Faizan Saeed Jun 21 '21 at 10:02
  • @Sohan I actually performed all of these steps but It wasn't working. – Faizan Saeed Jun 21 '21 at 10:03
  • Than it's a massive bug. I would like to reproduce it. Could you provide exact version of the affected database, version of the client you use, which OS you are using on the server and client side, output you get in the `mongod` from the moment of running the command to the moment when you observe the error on the client side. – Alex Blex Jun 21 '21 at 10:13
  • Also, see following post about how to go about creating the _user administrator_ first without authentication. Then, authenticate with this _user admin_ to create other users with access control. See [For mongo, not able to create users other than admin with error command createUser requires authentication :](https://dba.stackexchange.com/questions/292514/for-mongo-not-able-to-create-users-other-than-admin-with-error-command-createus) – prasad_ Jun 21 '21 at 10:45
  • @AlexBlex I am using 4.4.6 version of the mongodb server, Windows OS. Moreover, I am using mongodb on my local machine right now(server client both are on same machine). – Faizan Saeed Jun 21 '21 at 11:46
  • For output you can follow the this link. https://docs.mongodb.com/manual/tutorial/enable-authentication/ – Faizan Saeed Jun 21 '21 at 11:52
  • Sorry, I didn't get it. Are you using linux command to start mongod on Windows system? If it is wsl, which OS is it? Otherwise it should error with something like "there is no such command". Now the link. I can follow it but it points to the documentation. I asked about the actual output you have in the console where you started mongod - it should have information about what went wrong on your set up. – Alex Blex Jun 21 '21 at 12:57
  • If you reconnect using `-u` and `-p` those are passing in the credentials. – Joe Jun 22 '21 at 19:34

0 Answers0