springboot connecting to :mongodb://127.0..0.1:27017/test authentication failed

  • 投稿人: anan
  • 发布时间: 2021-07-23 17:04:28
  • 阅读: 287
  • 收藏: 16
  • 点赞: 1
  • 评论: 0


账号的权限不够,可能是insert进去的脚本的角色有问题

user admin 

db.createUser({user:'账号',pwd:'密码'
,roles:[{role:'userAdminAnyDatabase',db:'admin'},{role:'userAdmin',db:'admin'},{role:'readWrite',db:'admin'},{role:'dbAdmin',db:'admin'}
,{role:'clusterAdmin',db:'admin'},{role:'clusterManager',db:'admin'},{role:'clusterMonitor',db:'admin'},{role:'hostManager',db:'admin'}
,{role:'backup',db:'admin'},{role:'restore',db:'admin'},{role:'readWriteAnyDatabase',db:'admin'},{role:'dbAdminAnyDatabase',db:'admin'}
,{role:'readWrite',db:'xxxx'},{role:'dbAdmin',db:'xxxx'}
]})




mongo.conf的配置

dbpath=/usr/local/mongodb/data/db
logpath=/usr/local/mongodb/logs/mongodb.log
port=27017
logappend=true
fork=true
# 已后台的形式运行
maxConns=5000
#置参数为true
#configsvr=true
#允许任意机器连接
bind_ip=0.0.0.0
#开启用户认证true
auth=true
#复制副本集名称
#replSet=xxx

服务器端连接的命令

/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin -u 账号



springboot yml的配置

 

  data:
    mongodb:
      host: ip地址
      username: 账号
      password: 密码
      port: 27017
      authentication-database: admin
      database: xxxx

 

mongo启动命令

/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/mongodb.conf


关闭的命令(不要用kill,不然会造成启动不了)

/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/conf/mongodb.conf --shutdown