MENU

Mongodb创建修改用户权限 以及端口登录

May 6, 2019 • 已被 263 位童鞋围观过 • 代码分享

1 创建用户

db.createUser(
  {
    user: "user2",
    pwd: "user2",
    roles: [
       { role: "dbOwner", db: "db1" },
       { role: "clusterManager", db: "admin" }
    ]
  }
)

2 修改用户

db.updateUser(
    "user3",
    {
    customDate:{"any information"},
    roles: [
       { role: "dbOwner", db: "db1" },
       { role: "clusterManager", db: "admin" }
    ],
    pwd:"password"
    },
    writeconcem:{<write concem>}
)

3 端口登录

mongo --port 2888

Mongodb角色表:
|----------------角色分类-------------|---------角色---------|--------------------------------权限及角色------------------------|
|------Database User Roles-------|----------read--------| ----只读---- |
|------Database User Roles-------|-----readWrite------| -----读写----- |
|-Database Administration Role| -----dbAdmin------|--------collStats,dbHash,dbStats,find,等--------|
|-Database Administration Role| ------dbOwner-----| 角色:readWrite, dbAdmin,userAdmin |
|-Database Administration Role| -----userAdmin----| ChangeCustomData,ChangePassword,CreateRole,等 |
| ----------Superuser Roles---------|----------root------- | 角色:dbOwner,userAdmin, 等|

Last Modified: September 28, 2023