Docs HomeMongoDB Manual

Time Series Collection Limitations时间序列采集限制

This page describes limitations on using time series collections.本页介绍了使用时间序列集合的限制。

Unsupported Features不支持的功能

The following features are not supported for time series collections:时间序列集合不支持以下功能:

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 delete command.从MongoDB 5.1开始,您可以对时间序列集合执行有限的删除操作。MongoDB 7.0消除了基于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 the deleteMany() method.删除命令不得限制要删除的文档数。设置justOne: false或使用deleteMany()方法。

Starting in MongoDB 7.0, there is only one time series related limitation on these delete commands:从MongoDB 7.0开始,这些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 the updateMany() 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 expireAfterSeconds index property for partial indexes on the metaField. 从MongoDB 6.3开始,时间序列集合支持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:部分支持这些索引类型:

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及更早版本中:

  • The metaField can have secondary indexes.metaField可以具有辅助索引。
  • The timeField can have secondary indexes.timeField可以具有辅助索引。
  • If the metaField is a document, you can add secondary indexes on fields inside the document.如果metaField是文档,则可以在文档内部的字段上添加辅助索引。
Tip

See also: 另请参阅:

Indexes索引

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 metaFieldtimeFieldmetaField的修改

You can only set a collection's timeField and metaField parameters when you create the collection. You cannot modify these parameters later.创建集合时,只能设置集合的timeFieldmetaField参数。以后不能修改这些参数。

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或自定义bucketMaxSpanSecondsbucketRoundingSeconds参数后,可以增加它们,但不能减少它们。Use the collMod command to modify the parameters. 使用collMod命令可以修改参数。For example:例如:

db.runCommand({
collMod: "timeseries",
timeseries: { bucketMaxSpanSeconds: 3600, bucketRoundingSeconds: 3600 }
})
Note

bucketMaxSpanSeconds and bucketRoundingSeconds must be equal. bucketMaxSpanSecondsbucketRoundingSeconds必须相等。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 moveChunk) on the system.buckets collection.从MongoDB 5.2(和5.1.2、5.0.6)开始,您可以在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:指定分片关键帧时:

Tip

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.不能写入事务中的时间序列集合。

Note

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为前缀的集合)创建视图。