对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

创建本地 Atlas 部署

重要

从Atlas CLI版本 1.52.0 开始,atlas deployments 命令已弃用。请改用 atlas local 命令。我们更新了本教程以使用 atlas local 命令。

本教程向您展示如何使用 atlas local 命令创建本地Atlas部署。在本教程中,我们将在本地计算机上部署单节点副本集。然后,您可以管理部署,并使用MongoDB Search 和MongoDB Vector Search。

操作系统
操作系统版本
架构
最低 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

在开始之前,请完成以下步骤以满足先决条件:

重要

有关依赖项列表中每个产品的兼容性信息,请参阅该产品的安装文档。

1
  1. 安装 Atlas CLI。

    如果使用Homebrew,则可以在终端中运行以下命令:

    brew install mongodb-atlas-cli

    有关其他操作系统上的安装说明,请参阅安装或更新Atlas CLI。

  2. 安装 Docker。

    Docker需要网络连接来拉取和缓存MongoDB映像。

  3. (Optional) Install mongosh version 2.0 or later.

    brew install mongosh

    有关其他操作系统上的安装说明,请参阅安装mongosh。

  4. (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.

  5. (可选)安装Visual Studio Code和MongoDB for VS Code扩展。

    要学习;了解更多信息,请参阅安装MongoDB for VS Code扩展。

2

If you don't already have an existing Atlas account, run atlas setup in your terminal or create a new account.

使用 atlas local 命令创建本地 Atlas 部署。

可以通过以下方式运行该命令:

  • 交互模式(默认):该命令会提示您进行部署设置并提供默认值。

  • 交互模式(自定义):该命令会提示您进行部署设置,并允许您提供自定义值。

  • 非交互模式:使用指定选项运行该命令。该命令不会提示您提供其他值。要学习;了解atlas local 支持的所有操作,请参阅 atlas-local。

请单击以下标签页之一,查看首选模式的命令。

1
atlas local setup

要在设置期间加载MongoDB示例数据:

  1. 运行以下命令:

    atlas local setup --loadSampleData true

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas local setup --initdb {folder}
  2. 将 {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js 和 .sh 文件的目录。

  3. 运行命令。

2

示例:

指定 local - Local Database 并按 Enter..

? What would you like to deploy? [Use arrows to move, type to filter, ? for more help]
> local - Local Database
atlas - Atlas Database
[Default Settings]
Deployment Name local50
MongoDB Version 7.0
Port 27017
3

示例:

指定 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 部署。

1

示例:

atlas local list
NAME TYPE MDB VER STATE
local50 LOCAL 7.0.1 IDLE
local62 LOCAL 7.0.1 IDLE
myLocalRs LOCAL 7.0.1 IDLE
myLocalRs1 LOCAL 7.0.1 IDLE
2

注意

您还可以在部署设置期间使用 --loadSampleData true 选项和 atlas local setup 加载示例数据。请参阅上面的设置示例。

要将示例数据加载到现有部署中,请执行以下操作:

  1. 执行以下命令以下载示例数据。

    curl https://atlas-education.s3.amazonaws.com/sampledata.archive -o sampledata.archive
  2. 获取部署的端口号:

    1. 复制以下命令:

      atlas local connect <deployment name> --connectWith connectionString
    2. 将 <deployment name> 替换为您的部署名称。

    3. 运行命令。

      连接字符串包括端口号。示例,在连接字符串mongodb://localhost:27017/?directConnection=true 中,端口号为 27017。

  3. 将以下命令复制并粘贴到终端,然后将 {port-number} 替换为部署端口:

    mongorestore --archive=sampledata.archive --port={port-number}
3
  1. 运行以下命令以连接到部署:

    atlas local connect
  2. 指定要连接的部署并按 Enter..

  3. 指定您希望连接到部署的方式,然后按 Enter..

    您可以检索连接字符串或连接到以下客户端:连接字符串:

4
  1. 运行以下命令以暂停部署:

    atlas local stop
  2. 指定要暂停的部署并按 Enter..

5
  1. 运行以下命令以启动部署:

    atlas local start
  2. 指定要启动的部署并按 Enter..

6
  1. 运行以下命令以返回部署的日志:

    atlas local logs
  2. 指定要返回日志的部署并按 Enter..

  1. 运行以下命令以删除部署:

    atlas local delete
  2. 指定要删除的部署并按 Enter..

  3. 指定y并按Enter 。以确认。

您可以使用Docker和MongoDB Database Tools将本地Atlas部署迁移到云Atlas部署。

1
atlas setup
2
atlas local setup

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas local setup --initdb {folder}
  2. 将 {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js 和 .sh 文件的目录。

  3. 运行命令。

3
  1. 复制以下命令:

    docker exec -u root -it {local_deployment_name} sh -c "mkdir -p /data/dump && chown -R mongod:mongod /data/dump && mongodump --archive=/data/dump/dump.archive"
  2. 将 {local-deployment-name} 占位符替换为本地Atlas部署的名称。

  3. 运行命令。

4
  1. 复制以下命令:

    docker cp <local deployment name>:/data/dump/dump.archive .
  2. 将 {local-deployment-name} 占位符替换为本地Atlas部署的名称。

  3. 运行命令。

5
atlas clusters connectionStrings describe
6
  1. 复制以下命令:

    mongorestore --uri={connection-string} --archive=./dump.archive
  2. 将 {connection-string} 占位符替换为连接字符串。

  3. 运行命令。

7
atlas local delete

您可以使用Docker和MongoDB Database Tools将本地Atlas部署更新到较新版本的映像。

1
atlas local setup

要使用自己的数据和索引初始化本地Atlas部署,请执行以下操作:

  1. 复制以下命令:

    atlas local setup --initdb {folder}
  2. 将 {folder} 占位符替换为包含要在本地容器内按字母数字顺序运行的.js 和 .sh 文件的目录。

  3. 运行命令。

2
  1. 复制以下命令:

    docker exec -u root -it {old-local-deployment-name} sh -c "mkdir -p /data/dump && chown -R mongod:mongod /data/dump && mongodump --archive=/data/dump/dump.archive"
  2. 将 {old-local-deployment-name} 占位符替换为旧的本地Atlas部署的名称。

  3. 运行命令。

3
  1. 复制以下命令:

    docker cp {old-local-deployment-name}:/data/dump/dump.archive .
  2. 将 {old-local-deployment-name} 占位符替换为旧的本地Atlas部署的名称。

  3. 运行命令。

4
atlas local connect --connectWith connectionString
5
  1. 复制以下命令:

    mongorestore --uri={connection-string} --archive=./dump.archive
  2. 将 {connection-string} 占位符替换为连接环。

  3. 运行命令。

6
atlas local delete

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搜索索引并运行查询。

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部署问题。