重要
从Atlas CLI版本 1.52.0 开始,atlas deployments 命令已弃用。请改用 atlas local 命令。我们更新了本教程以使用 atlas local 命令。
本教程向您展示如何使用 atlas local 命令创建本地Atlas部署。在本教程中,我们将在本地计算机上部署单节点副本集。然后,您可以管理部署,并使用MongoDB Search 和MongoDB Vector Search。
本地 Atlas 部署支持的操作系统
操作系统 | 操作系统版本 | 架构 | 最低 CPU 核心数 | 最低可用RAM (GB) |
|---|---|---|---|---|
macOS | 13.2 及更高版本 | x86-64、ARM | 2 | 2 |
Red Hat Enterprise Linux/CentOS | 8, 9 | x86-64、ARM | 2 | 2 |
Ubuntu | 22.04 、 24.04 | x86-64、ARM | 2 | 2 |
Debian | 11, 12 | x86-64、ARM | 2 | 2 |
Amazon Linux | 2023 | x86-64、ARM | 2 | 2 |
Windows | 10, 11 | x86 | 2 | 2 |
满足先决条件
在开始之前,请完成以下步骤以满足先决条件:
重要
有关依赖项列表中每个产品的兼容性信息,请参阅该产品的安装文档。
安装依赖项。
安装 Docker。
Docker需要网络连接来拉取和缓存MongoDB映像。
对于 macOS 或 Windows,请安装 Docker 桌面 v4.31+。
对于 Linux,请安装 Docker Engine v27.0+。
对于Linux RHEL,您还可以使用 Podman v5.0+ 版本。
(Optional) Install Compass version 1.39.4 or later.
brew install mongodb-compass For installation instructions on other operating systems, see Download and Install Compass.
(可选)安装Visual Studio Code和MongoDB for VS Code扩展。
要学习;了解更多信息,请参阅安装MongoDB for VS Code扩展。
创建 Atlas 帐户。
If you don't already have an existing Atlas account, run atlas setup in your terminal or create a new account.
创建本地 Atlas 部署
使用 atlas local 命令创建本地 Atlas 部署。
可以通过以下方式运行该命令:
交互模式(默认):该命令会提示您进行部署设置并提供默认值。
交互模式(自定义):该命令会提示您进行部署设置,并允许您提供自定义值。
非交互模式:使用指定选项运行该命令。该命令不会提示您提供其他值。要学习;了解
atlas local支持的所有操作,请参阅atlas-local。
请单击以下标签页之一,查看首选模式的命令。
指定如何设置本地 Atlas 数据库。
示例:
指定 default - With default settings 并按 Enter..
? How do you want to setup your local MongoDB database? [Use arrows to move, type to filter] default - With default settings custom - With custom settings cancel - Cancel set up
Creating your deployment local50 [this might take several minutes] 1/4: Downloading and completing configuration... 2/4: Starting your local environment... 3/4: Downloading MongoDB binaries to your local environment... 4/4: Creating your deployment local50... Deployment created! Connection string: mongodb://localhost:27017/?directConnection=true
运行带有选项的atlas local 命令。
示例:
atlas local setup myLocalRs1 --force
[Default Settings] Deployment Name myLocalRs1 MongoDB Version 7.0 Port 49684 Creating your deployment myLocalRs1 1/2: Starting your local environment... 2/2: Creating your deployment myLocalRs1... Deployment created! Connection string: mongodb://localhost:49684/?directConnection=true connection skipped
要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:
复制以下命令:
atlas local setup myLocalRs1 --force --initdb {folder} 将
{folder}占位符替换为包含要在本地容器内按字母数字顺序运行的.js和.sh文件的目录。运行命令。
管理本地 Atlas 部署
使用 atlas local 命令管理本地 Atlas 部署。
加载样本数据。
注意
您还可以在部署设置期间使用 --loadSampleData true 选项和 atlas local setup 加载示例数据。请参阅上面的设置示例。
要将示例数据加载到现有部署中,请执行以下操作:
执行以下命令以下载示例数据。
curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive 通过运行以下命令并选择您的部署,获取对应您的部署的端口号。
atlas local connect --connectWith connectionString 连接字符串包括端口号。示例,在连接字符串
mongodb://localhost:27017/?directConnection=true中,端口号为27017。获取部署的端口号:
复制以下命令:
atlas local connect <deployment name> --connectWith connectionString 将
<deployment name>替换为您的部署名称。运行命令。
连接字符串包括端口号。示例,在连接字符串
mongodb://localhost:27017/?directConnection=true中,端口号为27017。
将以下命令复制并粘贴到终端,然后将
{port-number}替换为部署端口:mongorestore --archive=sampledata.archive --port={port-number}
连接到部署。
运行以下命令以连接到部署:
atlas local connect 指定要连接的部署并按
Enter..指定您希望连接到部署的方式,然后按
Enter..您可以检索连接字符串或连接到以下客户端:连接字符串:
MongoDB Compass(如果您安装了Compass)
Visual Studio Code(如果安装了Visual Studio Code、Visual Studio Code CLI和MongoDB for VS Code扩展)
删除Atlas部署
运行以下命令以删除部署:
atlas local delete 指定要删除的部署并按
Enter..指定
y并按Enter。以确认。
将本地Atlas部署迁移到 Cloud Atlas部署
您可以使用Docker和MongoDB Database Tools将本地Atlas部署迁移到云Atlas部署。
更新本地Atlas部署
您可以使用Docker和MongoDB Database Tools将本地Atlas部署更新到较新版本的映像。
将MongoDB Search 与本地Atlas部署结合使用
Use the atlas local search indexes create command to create an MongoDB Search search index. You can then run MongoDB Search queries. To learn more, see MongoDB Search.
有关详细步骤,请参阅创建MongoDB搜索索引并运行查询。
将MongoDB Vector Search 与本地Atlas部署结合使用
Use the atlas local search indexes create command to work with MongoDB Vector Search. To learn more, see How to Index Vector Embeddings for Vector Search.
有关详细步骤,请参阅在Atlas部署中使用MongoDB Vector Search。
重要
要将Atlas CLI与MongoDB Vector Search 结合使用,您必须使用MongoDB 7.0.5 或更高版本创建Atlas部署。如果使用早期MongoDB版本创建了本地Atlas部署,则不会自动获取最新的MongoDB版本。您必须删除早期的映像和部署。然后,您必须创建新的Atlas部署。
支持的操作
要学习;了解atlas local 支持的所有操作,请参阅 atlas-local。
故障排除错误
要学习;了解有关解决本地Atlas部署问题的更多信息,请参阅解决本地Atlas部署问题。