当前位置:Gxlcms > 数据库问题 > mongoDB 3.0.3 以上GUI 连接认证问题

mongoDB 3.0.3 以上GUI 连接认证问题

时间:2021-07-01 10:21:17 帮助过:2人阅读

port = 27017 2 3 auth = true 4 5 bind_ip = 0.0.0.0

修改这三行。

之后的问题就出在连接认证上了 ,mongoDB 3.0以后的版本认证变得复杂起来,连接工具都不能连接上,必须修改认证版本

> use admin 
switched to db admin 
>  var schema = db.system.version.findOne({"_id" : "authSchema"}) 
> schema.currentVersion = 3 
3 
> db.system.version.save(schema) 
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) 

在修改完成之后再创建用户。下面附带创建数据库用户的shell:

1 创建一个root用户:

use admin
db.createUser(
    {
      user: "superuser",
      pwd: "12345678",
      roles: [ "root" ]
    }
)

2 创建admin用户

use admin
db.createUser(
  {
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

3 创建具体数据库的用户

use records
db.createUser(
  {
    user: "recordsUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdmin", db: "records" } ]
  }
)

最后都要认证一下

db.auth("user", "pwd")

返回1代表成功,0代表失败。

mongoDB 3.0.3 以上GUI 连接认证问题

标签:

人气教程排行