重要
The feature described on this page is not currently supported on Atlas Infinite clusters during public preview. For the features supported in public preview, see Public Preview Availability.
配置在线存档后,可以执行以下操作:
重要
在线存档会使用 _id 和分片键从集群中删除文档。为防止发生数据丢失,请在执行分片操作前暂停存档;文档一旦符合存档条件,请勿更新;并确保应用程序中所有文档的 _id 均唯一。
必需的访问权限
要查看或查询在线存档,您必须具有该项目的 Project Read Only 或更高访问权限。
要编辑或删除在线存档,您必须具有该项目的 Project Data Access Admin 或更高访问权限。
查看在线存档
您可以通过 Atlas CLI、Atlas 用户界面和 API 查看集群的在线存档列表。
使用 Atlas CLI 检索在线存档
要使用 Atlas CLI 列出集群的所有在线存档,请运行以下命令:
atlas clusters onlineArchives list [options]
如需返回使用 Atlas CLI 指定的集群的详细信息,请运行以下命令:
atlas clusters onlineArchives describe <archiveId> [options]
要进一步了解前面命令的语法和参数,请参阅 atlas clusters onlineArchives list 和 atlas clusters onlineArchives describe 的 Atlas CLI 文档。
使用 API 检索在线存档
To retrieve an online archive through the API, send a GET request to the onlineArchives endpoint with the unique ID of the online archive to retrieve. To learn more about the API syntax and options, see API.
使用 API 检索集群的所有在线存档
To retrieve all the online archives configured for a cluster using the API, send a GET request to the onlineArchives endpoint for the cluster. To learn more about the syntax and options, see API.
在用户界面中查看在线存档
查看 Online Archive 列表:
AtlasGoClusters在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含所需项目的组织。
如果尚未显示,请从导航栏的Projects菜单中选择所需的项目。
在侧边栏中,单击 Database 标题下的 Clusters。
会显示集群页面。
该页面显示集群的在线存档。对于每个在线存档,可以看到以下信息:
注意
6 月7 、 2023发布的新指标值显示在Atlas用户界面中,仅适用于Date Match字段发布后创建的在线存档。 如果您创建时间序列 Online 存档 ,或者在发布日期之后有一个预先存在的在线存档,则Atlas会显示N/A而不是指标值。
列名称 | 说明 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Status | 在线存档的状态。 值可以是以下之一:
| ||||||||||||||
Actions | 您可以在 Online Archive 上执行的操作。 | ||||||||||||||
Archive Field | 基于存档文档的日期字段。 | ||||||||||||||
Custom Criteria | 自定义 JSON 过滤器。您可以在此代码组件中滚动。点击该图标展开视图以查看完整的自定义条件。 | ||||||||||||||
Age Limit | 用于确定文档存档资格的天数。 | ||||||||||||||
Deletion Age Limit | 删除存档中的数据之前的保留天数。 | ||||||||||||||
Total Data Archived | 存储在存档中的未压缩数据大小。 将鼠标悬停可查看存档中的文档数量。 指标仅适用于新的 Online Archive。 | ||||||||||||||
Last Archived Run | 上次运行存档的开始日期和时间戳。将鼠标悬停以查看最近五个作业。每个作业都会列出其开始日期、开始时间、存档持续时间、文档数量和大小。 | ||||||||||||||
Partition Fields | 其他常用查询字段用于对云对象存储上的数据进行分区。 | ||||||||||||||
Schedule | 存档窗口节奏。值包括:- | ||||||||||||||
Min Date Field | 存档中所有文档的最小日期值。 指标仅适用于Atlas Data Federation上的新 Online Archive。 | ||||||||||||||
Max Date Field | 存档中所有文档的最大日期值。 指标仅适用于Atlas Data Federation上的新 Online Archive。 |
查看在线存档性能指标。
要在 Atlas 用户界面中查看在线存档的指标,请执行以下操作:
在 Atlas 中,转到项目的联合数据库实例。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。
如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。
在侧边栏中,单击 Services 标题下的 Data Federation。
显示Data Federation 页面。
编辑存档规则
您可以修改在 Atlas 集群上保留数据的天数 (Age Limit) 或用于从 Atlas 用户界面和 API 选择要归档的文档的自定义 JSON 查询。您无法将存档条件从 Date Match 更改为 Custom Filter,反之亦然。
通过 Atlas CLI 编辑存档规则
要使用 Atlas CLI 为集群更新在线存档,请运行以下命令:
atlas clusters onlineArchives update <archiveId> [options]
To learn more about the command syntax and parameters, see the Atlas CLI documentation for atlas clusters onlineArchives update.
通过 API 编辑存档规则
To edit an online archive through the API, send a PATCH request to the onlineArchives endpoint with the unique ID of the online archive to update. To learn more about the API syntax and options, see API.
通过用户界面编辑存档规则
要编辑在线存档,请在 Atlas 用户界面中:
AtlasGoClusters在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含所需项目的组织。
如果尚未显示,请从导航栏的Projects菜单中选择所需的项目。
在侧边栏中,单击 Database 标题下的 Clusters。
会显示集群页面。
点击在线存档的 Actions 列中的省略号 (...) 以显示允许的操作列表。 您可以:
Pause Archiving (仅当状态为 Active(活动)时)
Edit Archive
Delete Archive
Resume Archiving (仅当状态为 Paused(活动)时)
从下拉列表中选择 Edit Archive,以更改存档规则、保留存档数据的天数以及运行数据存档作业的时间窗口。
可以更改存档条件和删除已存档数据前的保留天数。
要编辑 Date Match(日期匹配)条件,请修改 Archival Age Limit(存档时长限制)部分中 Atlas 在活动 Atlas 集群上存储数据的天数。
要编辑 Custom Criteria(自定义条件),请输入有效的 JSON 过滤器,以选择要存档的文档。
注意
Atlas uses the specified query with the db.collection.find(query) command. Custom queries do not support JavaScript expressions. Also, you can't pass an empty document
{}to return all documents.要修改 Atlas 删除已存档数据前的保留天数,请在 Deletion Age Limit(删除时长限制)部分输入或修改天数。可以指定
7到9125天,或将该字段留空以禁用数据过期规则。此更改需要 24 小时才能生效。要修改数据存档作业的计划时间,请对以下任一内容进行更改:
频率。您可以选择每天、一周中的特定日期或每月的特定日期运行作业。如果您希望在每月 29 日、30 日或 31 日进行存档,则 Atlas 在不包含这些日期的月份不会运行存档作业。
时间窗口。选择希望 Atlas 运行数据存档作业的时间段。必须指定至少两个小时。
还可以通过切换 Schedule Archive Window(计划存档窗口)来禁用计划。如果禁用计划,Atlas 将恢复默认计划并定期运行存档作业。
在您更改新的数据存档计划后,Atlas 会立即开始使用。但是,如果存档作业当前正在运行,Atlas 不会中断正在运行的作业,并且设置会在作业完成后生效。
编辑云对象存储上的分区
You can't modify the partition fields or structure from the Atlas UI or API. However, you can manually migrate the data from the cloud object storage using $merge, use $merge to rehydrate data back to Atlas cluster, delete the online archive, and then create a new online archive for the collection with the desired partition fields and structure.
查询在线存档
可以对已存档数据运行查询。
注意
Atlas Data Federation 使用不保留文档中字段顺序的列式存储。因此,Atlas Data Federation 不支持对存档数据执行字段顺序敏感的查询。
连接字符串
To run queries, you must first connect to your Online Archive. Your cluster connection string allows you to only query data in your Atlas cluster. To query your Online Archive, you must use one of the following:
连接到在线存档和集群 — 此只读连接字符串允许直接从实时集群读取数据。这会影响 IOPS 的可用资源以及在线存档中的可用资源。
连接到在线存档 — 此只读连接字符串只允许从在线存档读取数据,不会影响集群资源。
性能考虑因素
一般来说,查询存档数据比查询 Atlas 集群上的数据要慢得多。当您通过联合连接字符串查询集群和 Online Archive 中的数据时:
阻止查询(例如在返回结果之前消耗并处理发送至排序操作的所有输入文档的排序)具有与最慢存储(正在查询的存档)相关的性能特征。排序操作要求在返回结果之前对来源中的所有数据进行查询。
流媒体查询,例如查找,具有与被查询的最高性能存储 Atlas cluster 相关的性能特征。Atlas 在结果可用后立即返回结果,这意味着从存档返回结果比从 Atlas 集群返回结果需要更长的时间。
查询价格
对于联合查询和仅存档查询,您需要为以下项目支付费用。
数据扫描
在数据扫描期间,Atlas 会处理来自集群和存档的数据。Atlas 在集群上运行尽可能多的查询,以最大程度地减少需要扫描的数据量。例如,对于指定特定值的 match 查询,Atlas 仅从集群中检索具有指定值的文档。然后,Atlas 将检索到的文档与存档数据合并,然后返回。
对于需要访问底层集群中存储的所有数据的阻塞查询,Atlas 会检索所有数据。例如,对于 sort(没有 match),Atlas 会从集群和存档中检索所有数据进行排序。
数据访问
MongoDB 对您在存档中查询的每个分区收取费用。如果您的查询需要查询特定分区,MongoDB 会下载分区,并且每个下载的分区对应于一次访问。
数据搜寻
为了根据查询和查询字段查找分区,Atlas 对存档运行操作。Atlas 运行的每个此类操作最多可查找 1000 个分区。Atlas 运行最少数量的所需操作来查找满足查询所需的分区。例如,如果您的查询需要查询字段中涵盖的 100 个分区,则 Atlas 仅运行一项操作来满足查询。
数据传输
传输到联合基础架构的数据会产生数据传输成本。
删除在线存档
You can delete an online archive through the Atlas CLI, Atlas UI, and API. You delete the online archive manually. Five days after you delete an online archive, Atlas automatically deletes all the files and metadata on the online archive storage. After Atlas deletes this data, you can't restore it.
If you drop a database or collection configured for online archive, the data from the collection, if archived, continues to be available on the cloud object storage. You incur costs for storage on the cloud object storage. Alternatively, if you delete the cluster, Atlas deletes all the online archives configured for the cluster. This also deletes any archived data from the cloud object storage.
如果删除所有在线存档,也会删除联合数据库实例,并在再次创建在线存档时创建新的联合数据库实例。
删除在线存档后,其状态将变为 Deleted。如果同一数据库、集合和字段中没有其他在线存档处于 Active 状态,则可以为与已删除的在线存档相同的数据库、集合和字段创建另一个在线存档。
通过 Atlas CLI 删除在线存档
要使用 Atlas CLI 为集群删除在线存档,请运行以下命令:
atlas clusters onlineArchives delete <archiveId> [options]
To learn more about the command syntax and parameters, see the Atlas CLI documentation for atlas clusters onlineArchives delete.
从用户界面删除在线存档
要删除在线存档,请在 Atlas 用户界面中:
AtlasGoClusters在Atlas中,Go项目的 页面。
如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含所需项目的组织。
如果尚未显示,请从导航栏的Projects菜单中选择所需的项目。
在侧边栏中,单击 Database 标题下的 Clusters。
会显示集群页面。
点击在线存档的 Actions 列中的省略号 (...) 以显示允许的操作列表。 您可以:
Pause Archiving (仅当状态为 Active(活动)时)
Edit Archive
Delete Archive
Resume Archiving (仅当状态为 Paused(活动)时)
通过 API 删除在线存档
To delete an online archive through the API, send a DELETE request to the onlineArchives endpoint with the unique ID of the online archive to delete. To learn more about the syntax and options, see API.
删除标记为归档的时间序列存储桶
When Online Archive archives a time series collection, it first sets the internal control.closed field to true on each bucket that it marks for archival. After this field is set, the time series collection doesn't allow writes to the bucket. Inserts that would target the bucket write to another bucket or open a new one. Updates and deletes through the time series collection ignore the bucket.
如果您在在线存档从集群中删除这些存储桶之前删除在线存档,则这些存储桶将保留在集群上。对时间序列集合的删除操作会返回这些存储桶所包含文档的 deletedCount,即 0。
To remove these buckets, run a delete operation directly against the buckets. To run this operation, your database user must have the readWriteAnyDatabase role. The method depends on your MongoDB version:
对于早于 8.2 的 MongoDB 版本,请在
system.buckets.<collection>集合上运行删除操作。For MongoDB 8.2 and later, run the
deletecommand on the time series collection with therawData: trueoption.
警告
此过程将永久删除集群中的数据。在您删除存储桶之前,在线存档可能尚未将这些存储桶复制到在线存档中。在删除存储桶之前,请确认数据是否存在于备份或在线存档中,并验证过滤器是否仅匹配您打算删除的存储桶。
确定要删除的存储桶。
使用您计划用于删除操作的相同过滤器运行查询,并查看结果。将 <database>、<collection> 和 <timeField> 替换为您的值,并将 cutoff 设置为要删除存储桶之前的日期。
const cutoff = ISODate("2026-03-01T00:00:00Z"); db.getSiblingDB("<database>") .getCollection("system.buckets.<collection>") .find({ "control.closed": true, "control.max.<timeField>": { $lte: cutoff } }) .itcount()
删除存储桶。
const cutoff = ISODate("2026-03-01T00:00:00Z"); db.getSiblingDB("<database>") .getCollection("system.buckets.<collection>") .deleteMany({ "control.closed": true, "control.max.<timeField>": { $lte: cutoff } })
const cutoff = ISODate("2026-03-01T00:00:00Z"); db.getSiblingDB("<database>").runCommand({ delete: "<collection>", deletes: [ { q: { "control.closed": true, "control.max.<timeField>": { $lte: cutoff } }, limit: 0 } ], rawData: true })