Mongodb not authorized on admin to execute listDat

2020-07-22 17:44发布

问题:

After droping mongodb user ,not able to reconnect mongo again without authentication

i had created superuser tomuser

my command sequence in ubuntu terminal

1.use admin

2.db.dropUser('tomuser') true exit

3.sudo /etc/init.d/mongod stop

4.sudo /etc/init.d/mongod start

5.restart pc

6.mongo --port 27017

7.> show dbs 2016-01-14T16:03:55.420+0530 listDatabases failed:{ "ok" : 0, "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }", "code" : 13 } at src/mongo/shell/mongo.js:47


I am getting above error!! not authorized on admin to execute command

so ,not able to connect mongodb after dropping user ..?

is there any thing missing ...?

回答1:

1st way

I think there should be another user in the db.system.users. If so, please use the saved user to log in.

If there is NO users in the db.system.users

> db.system.users.find({})
  null

we can access mongodb through mongo --port 27017.

2nd way - Usual cause of problem

use sudo mongod --port 27017

instead of sudo mongod --auth --port 27017 --dbpath /var/lib/mongodb

note : --auth is only required when username & password authentication is setup



标签: mongodb