vscode 通过mongoose 连接mongodb atlas

 了解mongodb 的项目结构

vscode 通过mongoose 连接mongodb atlas_第1张图片

 1.代表集群名称 > 2.代表数据库名称>3.代表每个 collection名称

三者范围为从大到小的关系 (一对多)。每个集群有不同的连接地址、用户信息(Database Access)、ip配置信息(Network Access。

2.了解链接atlas几种方式

 vscode 通过mongoose 连接mongodb atlas_第2张图片

 1.通过 mongodb 桌面化工具连接

2.通过命令行连接

3.本文介绍的通过 vscode + mongoose 连接

4. 通过 sql工具连接。暂时先不了解

3.实践vscode 连接 atlas

下载 mongoose 插件

vscode 通过mongoose 连接mongodb atlas_第3张图片

 着重注意 databaseName 变量。从 atlas 复制连接的链接是没有的 。对应的就是 集群下面的数据库名字。这些地址建议配置到文件里面。

4。从 vscode + mongoose 写数据到 远程 数据库 

vscode 通过mongoose 连接mongodb atlas_第4张图片

 6.后续可以通过 express + mongoose 操作数据库。

提示:mongoose.model() 。 的第一个参数。对应的是 collection名字。但是在 atlas里面看到会是【uhis】 如果想保持不变那么 让第三个参数保持一致

vscode 通过mongoose 连接mongodb atlas_第5张图片

你可能感兴趣的:(mongodb,数据库)