0

all, I am new to mongoDB, and recently I am trying to set up a local env to try it, below is my step:

  1. Use docker to create a mongoDB container:

    docker run -d -name my-mongo -p 27017:27017 \
      -e MONGO_INITDB_ROOT_USERNAME=admin \
      -e MONGO_INITDB_ROOT_PASSWORD=Asdf1234 \
    mongo:4
    
  2. Then I use Studio 3T software to connect the admin database, and adds a new user named leon, below is the role I granted:

admin database users

  1. Then I create another database with the user leon :

create a new data base

  1. Test the connection, the result is OK:

Test connection of new database

  1. Connect to the new database, and right click on the Manage users menu:

right click manage users menu

  1. But it always reports the non-authorized error:

non authorized error

Does anybody know the detail reason ?

ahwyX100
  • 585
  • 2
  • 9
  • 22
  • Please don't paste screenshots, use formatted text. See https://meta.stackoverflow.com/q/285551 – Wernfried Domscheit Jun 05 '23 at 06:44
  • I assume user `leon` has been created twice. Once in database `admin` and once in database `tailchat`. Check all existing users with command `db.getSiblingDB('admin').getCollection('system.users').find({})`. See [Authentication Database](https://www.mongodb.com/docs/manual/core/security-users/#authentication-database). Honestly, I am not aware of any reason why user should be created anywhere else than in `admin` (or `$external` in case of X.509 or LDAP authentication) database. – Wernfried Domscheit Jun 05 '23 at 06:53
  • Try running the [connectionStatus](https://www.mongodb.com/docs/manual/reference/command/connectionStatus/#connectionstatus) command to see which user and roles that connection currently uses. – Joe Jun 05 '23 at 18:40

0 Answers0