当前位置: 首页 > Linux

线上环境连接mongodb的问题

时间:2023-04-06 04:37:00 Linux

新的服务器上安装了mongodb,没有做之前项目的数据库信息测试。首先通过命令行登录数据库mongo--port27019-utest然后输入数据库密码创建数据库使用test是使用showdbs命令查看数据库。由于新建的数据库test不在数据库列表中,要显示出来,我们需要往test数据库中插入一些数据。>db.xxx.insert({"name":"test"})WriteResult({"nInserted":1})>showdbsadmin0.000GBconfig0.000GBlocal0.000GBtest0.000GB创建数据库后,由于新环境,测试用户无法访问测试库。需要重新创建test用户并授予读写权限db.createUser({user:"test",pwd:"123456@2022",roles:[{role:"readWrite",db:"test"}]})然后需要将数据库切换到vms_202106,使用db.auth命令授权使用testdb.auth('test','123456@2022')授权后在项目中使用如下配置连接mongodbspring:data:mongodb:#用户名密码格式为用户名:密码特殊符号需要使用传输符#@的传输符为%40uri:mongodb://test:123456%402022@127.0.0.1:27019/testdatabase:test选项:socket-keep-alive:true#max-connection-idle-time:6000connect-timeout:3600min-connection-per-host:100threads-allowed-to-block-for-connection-multiplier:5max-wait-time:10000socket-timeout:0max-connection-life-time:0heartbeat-socket-超时:3600心跳连接超时:3600最小心跳频率:5心跳频率:10