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

后端 未结 6 880
既然无缘
既然无缘 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 20:03

    Once you are connected to this first node, you can initiate the replica set with rs.initiate(). Again, this command must be run from the same host as the mongod to use the localhost exception.

    We can create our admin user with the following commands:

    rs.initiate()
    use admin
    db.createUser({
      user: "admin",
      pwd: "pass",
      roles: [
        {role: "root", db: "admin"}
      ]
    })
    

提交回复
热议问题