show dbs gives “Not Authorized to execute command” error

前端 未结 7 1379
暖寄归人
暖寄归人 2020-12-24 13:42

I\'ve spent some time trying to figure out what is wrong but as I could not find out, I decided to ask here.

I am running MongoDB(Windows 64-bit 2008 R2+) version 3.

7条回答
  •  佛祖请我去吃肉
    2020-12-24 14:15

    Create a user like this:

    db.createUser(
          {
            user: "myUserAdmin",
            pwd: "abc123",
            roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
          }
        )
    

    Then connect it following this:

    mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
    

    Check the manual :

    https://docs.mongodb.org/manual/tutorial/enable-authentication/

提交回复
热议问题