使用mLab构建MongoDB环境和导入示例数据的方法
首先
本文介绍了如何使用MongoDB的PaaS平台mLab来配置MongoDB环境,并介绍了向该环境中创建的数据库导入示例数据的方法。
另外,mLab的环境适用于免费版和Windows环境的使用。
注册mLab账户
首先,访问以下网址并获取mLab账户。
https://mlab.com/home 的網站提供線上資料庫應用程式的服務。

请输入任意的用户ID、电子邮件地址和密码,以获取账户。

完成注册后,确认邮件将发送至您输入的电子邮箱地址。确认电子邮箱地址后,将可以创建数据库。
在mLab上创建数据库
完成邮件地址确认后,我们将执行MongoDB的数据库创建。
当您登录到mLab时,将显示以下屏幕,然后请点击“MongoDB部署”下的“+Create New”。

在mLab中,您可以从AWS、GCP和Azure中选择要创建的环境。在本文中,我们选择了AWS,但无论您选择哪个都可以。
选择环境后,在屏幕底部点击“继续”,然后选择免费版本环境的“沙盒”。

请继续选择所需的地区,然后点击“继续”。

最后,输入所需MongoDB数据库的名称,然后点击“继续”。

在确认输入内容之后,点击“提交订单”即可配置MongoDB环境。

创建mLab用户
接下来,我们将创建用于访问MongoDB的MongoDB用户信息。
选择之前创建的MongoDB数据库。

请点击「用户」选项卡,然后再点击「添加数据库用户」。

在这里输入任意的用户名和密码,然后点击“创建”,即可完成用户创建。

上述的内容表示,mLab的环境准备已经完成。
安装Mongo Import/Export工具
接下来,为了将示例数据导入mLab的MongoDB数据库,我们需要安装MongoDB Shell的导入/导出工具。
访问以下网址,下载MongoDB的安装程序。
请访问以下链接下载MongoDB:https://www.mongodb.com/download-center?jmp=nav#community

这个安装程序包含了MongoDB的核心以及其他实用工具和工具,如MongoShell。

这次所需的只是Import/Export工具。如果选择了Complete,则会安装Import/Export工具。

您可以选择从自定义设置中仅选择导入/导出工具来安装。

将样本数据导入到数据库
完成安装导入/导出工具后,使用该工具进行示例数据导入。
我们将使用以下URL公开的样本数据。
请将以下内容翻译成中文:https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/primer-dataset.json。
下载完成后,移动到以下文件夹并打开命令提示符。
「C:\Program Files\MongoDB\Server\3.4\bin」的中文翻译是 “C:\程序文件\MongoDB\服务器\3.4\二进制文件夹”。

你需要在以下命令中输入目标文件名以及所获取的mLab MongoDB环境,并执行MongoImport。
mongoimport --collection Sample --file primer-dataset.json --host XXXX.mlab.com --port XXXX --db XXXXXX --username XXXXX --password XXXX
在安装完成后,您可以在mLab上验证数据。点击Collection标签,然后选择添加的Sample Collection。

只需一种选项,以下是可以确认样本数据已注册的方式。

总结
以上已经完成了由mLab搭建MongoDB环境和导入样本数据。