关于后端:线上环境连接mongodb出现的问题

在一台新的服务器装置了mongodb,没有之前我的项目的数据库信息test,首先通过命令行形式登陆数据库
mongo --port 27019 -u test
而后输出数据库明码

创立数据库

use test

在应用 show dbs命令查看数据库,因为刚创立的数据库 test并不在数据库的列表中, 要显示它,咱们须要向 test数据库插入一些数据。

> db.xxx.insert({"name":"test"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
test  0.000GB

在创立完数据库之后,因为为新的环境,test用户不能够拜访test库,须要从新创立test用户并授读写权限

db.createUser({user:"test",pwd:"[email protected]",roles:[{role:"readWrite",db:"test"}]})

而后须要切换数据库到vms_202106中,应用db.auth命令受权

use test
db.auth('test','[email protected]')

受权后,在我的项目中应用如下配置连贯mongodb

spring:
  data:
    mongodb:
      # 用户名明码格局为 用户名:明码 特殊符号须要应用转移字符
      # @的转移字符为%40
      uri: mongodb://test:123456%[email protected]:27019/test
      database: test
      option:
        socket-keep-alive: true
#        max-connection-idle-time: 6000
        connect-timeout: 3600
        min-connection-per-host: 100
        threads-allowed-to-block-for-connection-multiplier: 5
        max-wait-time: 10000
        socket-timeout: 0
        max-connection-life-time: 0
        heartbeat-socket-timeout: 3600
        heartbeat-connect-timeout: 3600
        min-heartbeat-frequency: 5
        heartbeat-frequency: 10

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理