[英 => 中] MongoDB 起步
原文地址 起步是一个针对供应,运行,监测,维护 MongoDB 部署的云托管服务。它是入门 MongoDB 快速,简单,免费的一个方式。想在本地安装和运行 MongoDB,查阅 学习关于 MongoDB 查询语言和其它 MongoDB 原理,注册 1 创建一个 Altas 用户账户开始学习 MongoDB Atlas,创建你的用户账户并登录 Atlas。 2 创建一个 Atlas Group给你的 group 选择一个名字。 Groups 管理相关的 MongoDB 部署。创建额外的 Atlas groups,点击右上角你的用户名并选择 My Groups。点击 Add Group 按钮。 3 创建一个 clusterMongoDB 部署,或 Atlas 中的 “clusters”,可以是 或 创建 cluster,进入 Clusters 视图并点击 Add New Cluster 或 Build a New Cluster 按钮。 1.输入 Cluster Name 这些字段只在你的 Atlas group 没有 MongoDB 用户存在时出现。如果你事先在 group 创建了用户这些不会出现。 4.点击 Confirm & Deploy 4 设置安全功能Atlas 只允许从 group's whitelist 中的客户端连接到 cluster。添加入口到 whitelist: 1.从 Clusters 视图点击 Security 标签 5 下载连接客户端下载 Shell: 1.在 Clusters 视图点击 Connenct 按钮 需要更多操作系统具体的安装信息,查阅 6 获取 URI 连接字符串从 MongoDB Atlas Clusters 视图: 1.点击 Connect 按钮查看 7 连接 cluster使用上一步的 URI string,连接到 Atlas cluster:
如果你添加了
Windows 中,运行:
Documents 和 CollectionsMongoDB 在 中以 存储数据。MongoDB 数据库存储 documents 的 collections。 Insert Documents能 insert 多个 documents 到 collection。给这个方法传入一个 documents 到数组。 下面的示例 inserts 新的 documents 到 inventory collection:
insertMany() 返回一个包含最新 inserted 的 documents _id 字段值。查阅 示例。 使用 insert 单个 document。 更多信息和示例,查阅 部分的 。 Query Documents选择所有 Documents在 collection 中选择所有 documents,给 方法传入空的 document 作为
要查询特定的 documents,给 find() 方法传入一个要查询的 documents,形式为
匹配 Embedded Document在整个 embedded document 上的 equality matches 需要指定
在 Embedded Document 中匹配一个字段下面的示例选择所有 size 中 uom 等于 “in” 的 documents:
匹配数组中的元素下面的示例查询所有 tags 数组中包含 “red” 元素的 documents:
精确匹配数组下面的示例精确查询所有 tags 数组为指定顺序的 2 个元素 “red” 和 “blank” 的 document:
更多信息和查询示例,查阅 部分的 。 要更新或删除 documents,查阅 和 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |