What MongoDB user privileges do I need to add a user to a new/another mongo database?

后端 未结 2 1036
生来不讨喜
生来不讨喜 2020-12-23 15:33

I have enabled authentication in the MongoDB config file after adding one admin user with the following privileges: userAdmin and userAdminAnyDatabase

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 15:44

    This is what worked for me for creating a user prod who connects to database prod assuming I had an admin user (called admin) already in the MongoDB:

    > mongo admin --username root --password 
    > use prod
    > db.createUser(
      {
        user: "prod",
        pwd: "",
        roles: [ { role: "dbOwner", db: "prod" } ]
      }
    )
    > exit
    

    After this you can login with the new user prod like this:

    > mongo prod  --username prod --password 
    

提交回复
热议问题