Time Series Collection Limitations时间序列采集限制
On this page本页内容
Unsupported Features不支持的功能Aggregation $merge聚合$merge
Deletes删除Updates更新Time Series Secondary Indexes时间序列辅助索引Time Series Secondary Indexes时间序列辅助索引Time Series Secondary Indexes with MongoDB 5.0 and EarlierMongoDB 5.0及更早版本的时间序列辅助索引Capped Collections封顶集合Modification of Collection Type修改集合类型Modification oftimeField
andmetaField
timeField
和metaField
的修改Modifying Bucket Parameters修改桶参数Sharding分片Sharding Administration Commands共享管理命令Shard Key Fields分片键段Resharding重新分片Transactions事务Views视图
This page describes limitations on using time series collections.本页介绍了使用时间序列集合的限制。
Unsupported Features不支持的功能
The following features are not supported for time series collections:时间序列集合不支持以下功能:
Atlas SearchAtlas搜索Change streams更改流Client-Side Field Level Encryption客户端字段级加密Database Triggers数据库触发器GraphQL APIGraphQL APISchema validation rules架构验证规则reIndex
renameCollection
Atlas Device Sync is only supported if the time series collections are asymmetrically synchronized. 仅当时间序列集合不对称同步时才支持。For details, see Enable Atlas Device Sync.有关详细信息,请参阅启用Atlas设备同步。
Aggregation $merge聚合$merge
You cannot use the 不能使用$merge
aggregation stage to add data from another collection to a time series collection.$merge
聚合阶段将其他集合中的数据添加到时间序列集合中。
Deletes删除
Starting in MongoDB 5.1, you can perform limited delete operations on time series collections. MongoDB 7.0 removes most limitations from operations that are based on the 从MongoDB 5.1开始,您可以对时间序列集合执行有限的删除操作。MongoDB 7.0消除了基于delete
command.delete
命令的操作的大多数限制。
Time series deletes are not supported for multi-document transactions.多文档事务处理不支持时间序列删除。
From MongoDB 5.1 to 6.3, delete commands must meet the following requirements:从MongoDB 5.1到6.3,delete命令必须满足以下要求:
You can only match on metaField field values.只能在metaField字段值上匹配。Your delete command must not limit the number of documents to be deleted. Set删除命令不得限制要删除的文档数。设置justOne: false
or use thedeleteMany()
method.justOne: false
或使用deleteMany()
方法。
Starting in MongoDB 7.0, there is only one time series related limitation on these 从MongoDB 7.0开始,这些delete
commands:delete
命令只有一个与时间序列相关的限制:
You cannot use these commands with multi-document transactions. There are no other restrictions.不能将这些命令用于多文档事务。没有其他限制。
If a time series collection contains documents with 如果时间序列集合包含timeField
timestamps before 1970-01-01T00:00:00.000Z
or after 2038-01-19T03:14:07.000Z
, no documents are deleted from the collection by the TTL "time to live" feature.timeField
时间戳在1970-01-01T00:00:00.000Z
之前或2038-01-19T03:14:07.000Z
之后的文档,则TTL“生存时间”功能不会从集合中删除任何文档。
For details on TTL deletes, see Expire Data from Collections by Setting TTL.有关TTL删除的详细信息,请参阅通过设置TTL使集合中的数据过期。
Updates更新
Starting in MongoDB 5.1, you can perform limited update operations.从MongoDB 5.1开始,您可以执行有限的更新操作。
Update commands must meet the following requirements:更新命令必须满足以下要求:
You can only match on the只能在metaField
field value.metaField
字段值上匹配。You can only modify the您只能修改metaField
field value.metaField
字段值。Your update document can only contain update operator expressions.更新文档只能包含更新运算符表达式。Your update command must not limit the number of documents to be updated.更新命令不得限制要更新的文档数。Set设置multi: true
or use theupdateMany()
method.multi:true
或使用updateMany()
方法。Your update command must not set upsert: true.您的更新命令不得设置upsert: true
。
In MongoDB 5.0, time series collections only support insert operations and read queries. Updates and manual delete operations result in an error.在MongoDB 5.0中,时间序列集合只支持插入操作和读取查询。更新和手动删除操作会导致错误。
To automatically delete old data, set up automatic removal (TTL).要自动删除旧数据,请设置自动删除(TTL)。
To remove all documents from a collection, use the 若要从集合中删除所有文档,请使用drop()
method to drop the collection.drop()
方法删除集合。
Time Series Secondary Indexes时间序列辅助索引
MongoDB 6.0 and later features improved support for secondary indexes on time series collections. MongoDB 6.0及更高版本的功能改进了对时间序列集合的辅助索引的支持。For a summary of these options, see Time Series Secondary Indexes in MongoDB 6.0 and Later.有关这些选项的摘要,请参阅MongoDB 6.0及更高版本中的时间序列辅助索引。
Time Series Secondary Indexes时间序列辅助索引
Starting in MongoDB 6.3, time series collections support the 从MongoDB 6.3开始,时间序列集合支持expireAfterSeconds
index property for partial indexes on the metaField
. metaField
上部分索引的expireAfterSeconds
索引属性。For earlier versions of MongoDB, use the collection level expireAfterSeconds parameter.对于MongoDB的早期版本,请使用集合级别的expireAfterSeconds参数。
Starting in MongoDB 6.0, you can add a secondary index to any field.从MongoDB 6.0开始,您可以向任何字段添加辅助索引。
These index types are partially supported:部分支持这些索引类型:
You can only create multikey indexes on the您只能在metaField
.metaField
上创建多键索引。You can only create sparse indexes on the只能在metaField
.metaField
上创建稀疏索引。
These index types aren't supported:不支持以下索引类型:
If there are secondary indexes on time series collections and you need to downgrade the feature compatibility version (FCV), you must first drop any secondary indexes that are incompatible with the downgraded FCV. 如果时间序列集合上有辅助索引,并且需要降级功能兼容性版本(FCV),则必须首先删除与降级的FCV不兼容的所有辅助索引。See 请参阅setFeatureCompatibilityVersion
.setFeatureCompatibilityVersion
。
Time Series Secondary Indexes with MongoDB 5.0 and EarlierMongoDB 5.0及更早版本的时间序列辅助索引
In MongoDB 5.0 and earlier:在MongoDB 5.0及更早版本中:
ThemetaField
can have secondary indexes.metaField
可以具有辅助索引。ThetimeField
can have secondary indexes.timeField
可以具有辅助索引。If the如果metaField
is a document, you can add secondary indexes on fields inside the document.metaField
是文档,则可以在文档内部的字段上添加辅助索引。
See also: 另请参阅:
Capped Collections封顶集合
You cannot create a time series collection as a capped collection.不能将时间序列集合创建为封顶集合。
Modification of Collection Type修改集合类型
You can only set the collection type when you create a collection:您只能在创建集合时设置集合类型:
An existing collection cannot be converted into a time series collection.无法将现有集合转换为时间序列集合。A time series collection cannot be converted into a different collection type.时间序列集合无法转换为其他集合类型。
To move data from an existing collection to a time series collection, migrate data into a time series collection.要将数据从现有集合移动到时间序列集合,请将数据迁移到时间序列集中。
Modification of timeField
and metaField
timeField
和metaField
的修改
timeField
and metaField
You can only set a collection's 创建集合时,只能设置集合的timeField
and metaField
parameters when you create the collection. You cannot modify these parameters later.timeField
和metaField
参数。以后不能修改这些参数。
Modifying Bucket Parameters修改桶参数
Once you set a collection's 设置集合的granularity
or custom bucketing parameters bucketMaxSpanSeconds
and bucketRoundingSeconds
, you can increase them, but not decrease them. granularity
或自定义bucketMaxSpanSeconds
和bucketRoundingSeconds
参数后,可以增加它们,但不能减少它们。Use the 使用collMod
command to modify the parameters. collMod
命令可以修改参数。For example:例如:
db.runCommand({
collMod: "timeseries",
timeseries: { bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600 }
})
bucketMaxSpanSeconds
and bucketRoundingSeconds
must be equal. bucketMaxSpanSeconds
和bucketRoundingSeconds
必须相等。If you modify one parameter, you must also set the other to the same value.如果修改一个参数,还必须将另一个参数设置为相同的值。
Sharding分片
Starting in MongoDB 5.1 (and 5.0.6), you can create sharded time series collections.从MongoDB 5.1(和5.0.6)开始,您可以创建分片的时间序列集合。
In versions earlier than MongoDB 5.0.6, you cannot shard time series collections.在MongoDB 5.0.6之前的版本中,不能对时间序列集合进行分片。
Sharding Administration Commands共享管理命令
Starting in MongoDB 5.2 (and 5.1.2, 5.0.6), you can run sharding administration commands (such as 从MongoDB 5.2(和5.1.2、5.0.6)开始,您可以在moveChunk
) on the system.buckets
collection.system.buckets
集合上运行分片管理命令(如moveChunk
)。
In versions earlier than MongoDB 5.0.6, you cannot run sharding administration commands for sharded time series collections.在MongoDB 5.0.6之前的版本中,您不能为分片的时间序列集合运行分片管理命令。
Shard Key Fields分片键段
When sharding time series collections, you can only specify the following fields in the shard key:对时间序列集合进行分片时,只能在分片键中指定以下字段:
- The
metaField
- Sub-fields of
metaField
- The
timeField
You may specify combinations of these fields in the shard key. 您可以在分片键中指定这些字段的组合。No other fields, including 在分片键模式中不允许使用其他字段,包括_id
, are allowed in the shard key pattern._id
。
When you specify the shard key:指定分片关键帧时:
metaField
can be either a:可以是:timeField
must be:必须是:A ranged shard key远程分片键At the end of the shard key pattern在分片键模式的末尾
Avoid specifying only the 避免仅将timeField
as the shard key. timeField
指定为分片键。Since the 由于timeField
increases monotonically, it may result in all writes appearing on a single chunk within the cluster. timeField
单调增加,它可能导致所有写入都出现在集群内的单个块上。Ideally, data is evenly distributed across chunks.理想情况下,数据在块之间均匀分布。
To learn how to best choose a shard key, see:要了解如何最好地选择分片键,请参阅:
Resharding重分片
You cannot reshard sharded time series collections.无法重新共享已分片的时间序列集合。
Transactions事务
You cannot write to time series collections in transactions.不能写入事务中的时间序列集合。
Reads from time series collections are supported in transactions.事务中支持从时间序列集合读取。
Views视图
Time series collections are writable non-materialized views. Limitations for views apply to time series collections.时间序列集合是可写的非物化视图。视图的限制适用于时间序列集合。You cannot create a view from a time series bucket collection namespace (namely, a collection prefixed with不能从时间序列桶集合命名空间(即以system.buckets
).system.buckets
为前缀的集合)创建视图。