安装了mongodb之后,mongodb默认绑定的ip地址是本机ip地址127.0.0.1。因此我们需要更改其配置文件(最好看官网的说明,很多博客的版本都过时了)。
官方参考:https://docs.mongodb.com/master/reference/configuration-options/#net-options。

在linux下我们打开mongod.conf配置文件
然后将bindIp设置为0.0.0.0,bindIpAll设置为true即可。

然后重启mongodb
sudo service mongod restart
然后我们连接阿里云服务器的mongodb数据库。

连接成功后:

网友评论