9

创建并取得Mongodb Altas账户并取得连接字符串

 3 years ago
source link: https://www.taterli.com/7691/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

创建并取得Mongodb Altas账户并取得连接字符串

Mongodb Altas是提供免费Mongodb数据库的地方,我的很多程序都用他提供的数据库,主要一个好处就是免费,多处连接,不用自己本机部署,SQLite虽然方便,但是需要自己部署,也不方便多处连接,比如多个不同的服务器.

打开网站只有各Start free,不用想就是这里注册账户,虽然不用邮箱验证,但是还是必须填真的邮箱,不然你的数据哪安全呢.

网址:https://www.mongodb.com/

然后创建Project,选哪个语言都无所谓,我这里选了Go.

不用想,我们当然选免费的.

挑一个距离你服务器比较近的地方(比如脚本放法国,不可能选香港吧!),然后继续就行.

然后修改数据库的防火墙,在左边的Network Access里面,选择Add IP Address,填入CIDR,如果不会,选择[ALLOW ACCESS FROM ANYWHERE]也行,然后确认.

然后到左边的Database Access里面,选择Add New Database User,输入一个数据库用户名和密码,这个密码不一定要等于用户密码的.然后确认就可以,比如我这里设置的密码是6PJ5kiPrn&^gBz,用户名是nickfox.

然后回到Clusters里面,等他创建完成后,点CONNECT,.选[Connect your application],现在红框的就是连接字符串.

我这里得到的字符串是:mongodb+srv://nickfox:@cluster0.te91y.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

根据我之前设置的用户名密码,套进去等于:mongodb+srv://nickfox:6PJ5kiPrn&^[email protected]/?retryWrites=true&w=majority

然后填到程序里面就可以使用了.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK