When creating first admin user on mongdb cluster getting error “couldn't add user: not authorized on admin to execute command”

后端 未结 6 883
既然无缘
既然无缘 2021-02-04 19:10

I am using mongoDB Cluster with version 3.4 in google cloud compute engine, actually past week my database got attacked by hackers that\'s why i thought about using authorizatio

6条回答
  •  孤独总比滥情好
    2021-02-04 19:55

    To be able to create a new user, you need to first disable security in /etc/mongod.conf

    // security: // authorization: enabled Then restart Mongodb server sudo service mongo restart

    After this you can add the user and role that you want from the shell.

    db.createUser({ user: 'test_user', pwd: 'test', roles: [ { role: "userAdmin", db: "test" }, { role: "dbAdmin", db: "test" }, { role: "readWrite", db: "test" } ] })

    To enable authenticated connection Uncomment the line again in /etc/mongod.conf

    security: authorization: enabled and restart the server again

提交回复
热议问题