开启远程连接

How to enable MongoDB for remote access

创建用户

默认安装以后没有用户

1
2
3
4
5
6
# 进入cli命令界面
mongosh

# switch to admin user

use admin

去创建admin 用户,用于密码验证连接 用户名 ins,执行以后输入密码。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
db.createUser(
  {
    user: "ins",
    pwd: passwordPrompt(), // or cleartext password
    roles: [
      { role: "userAdminAnyDatabase", db: "admin" },
      { role: "readWriteAnyDatabase", db: "admin" }
    ]
  }
)

开启用户 auth + 远程连接

sudo nano /etc/mongod.conf

1
2
3

security:
    authorization: enabled

systemctl restart mongod

允许 ip,我这里本地,就填写的不限制。

至此,远程连接已经开启。 接下去,测试一下。 下载软件 Mongodb compass 下载地址

一个GUI

ip username password save & connect

连接成功,远程连接开启成功。

Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy