Time Series Collection Notes and Limitations时间序列集合注释和限制

On this page本页内容

Constraints约束条件

The maximum size of a measurement document is 4 MB.测量文档的最大大小为4MB。

Updates and Deletes更新和删除

Starting in MongoDB 5.1, you can perform some delete and update operations.从MongoDB 5.1开始,您可以执行一些删除和更新操作。

Delete commands must meet the following requirements:删除命令必须满足以下要求:

  • The query may only match on metaField field values.查询只能在metaField值上匹配。
  • The delete command may not limit the number of documents to be deleted. delete命令可能不会限制要删除的文档数量。You must use a delete command with justOne: false or the deleteMany() method.必须使用删除命令配合justOne:falsedeleteMany()方法。

Update commands must meet the following requirements:更新命令必须满足以下要求:

  • The query may only match on metaField field values.查询只能在metaField值上匹配。
  • The update command may only modify the metaField field value.更新命令只能修改metaField值。
  • The update must be performed with an update document that contains only update operator expressions.必须使用仅包含更新运算符表达式的更新文档执行更新。
  • The update command may not limit the number of documents to be updated. update命令可能不会限制要更新的文档数量。You must use an update command with multi: true or the updateMany() method.必须使用更新命令配合multi:trueupdateMany()方法。
  • The update command may not set upsert: true.更新命令不能设置upsert: true

In MongoDB 5.0, Time series collections only support insert operations and read queries. 在MongoDB 5.0中,时间序列集合只支持插入操作和读取查询。Updates and manual delete operations result in an error.更新和手动删除操作会导致错误。

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()方法删除集合。

Secondary Indexes二级索引

You can add secondary indexes on the fields specified as the timeField and the metaField. 可以在指定为timeFieldmetaField的字段上添加二级索引If the field value for the metaField field is a document, you can also create secondary indexes on fields inside that document.如果metaField字段的字段值是文档,则还可以在该文档内的字段上创建二级索引。

In MongoDB 5.1, the metaField doesn't support text indexes.在MongoDB 5.1中,metaField不支持text索引。

In MongoDB 5.0, the metaField doesn't support the following index types:在MongoDB 5.0中,metaField不支持以下索引类型:

Secondary indexes don't support the following index properties:二级索引不支持以下索引属性:

  • 2d in MongoDB 5.2 and lower在MongoDB 5.2及更低版本中
  • 2dsphere in MongoDB 5.2 and lower在MongoDB 5.2及更低版本中
  • TTL
  • Unique
  • Partial in MongoDB 5.2 and lower在MongoDB 5.2及更低版本中
  • Multikey index on a measurement field在测量字段上

reIndex

The reIndex command is not supported for time series collections.时间序列集合不支持reIndex命令。

Capped Collections封顶集合

A time series collection can't be created as a capped collection.无法将时间序列集合创建为封顶集合

Modification of Collection Type修改集合类型

A collection's type can only be set when creating the collection:只能在创建集合时设置集合的类型:

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 creating the collection. 创建集合时,只能设置集合的timeFieldmetaField参数。After creation these parameters can't be modified.创建后,无法修改这些参数。

Modification of granularitygranularity修正

Once the granularity is set it can only be increased by one level at a time. 一旦设置了granularity,一次只能增加一个级别。From "seconds" to "minutes" or from "minutes" to "hours". "seconds""minutes",或从"minutes""hours"Other changes are not allowed. 不允许进行其他更改。If you need to change the granularity from "seconds" to "hours", first increase the granularity to "minutes" and then to "hours".如果需要将granularity"seconds"更改为"hours",请先将粒度增加到"minutes",然后再增加到"hours"

Schema Validation架构校验

You cannot specify validation rules for time series collections.不能为时间序列集合指定校验规则

Client-Side Field Level Encryption客户端字段级加密

Client-side field level encryption is not supported for time series collections.时间序列集合不支持客户端字段级加密

Sharding分片

Starting in MongoDB 5.1 (and 5.0.6), sharded time series collections are supported. 从MongoDB 5.1(和5.0.6)开始,支持分片时间序列集合。When using sharded time series collections, you cannot modify the granularity of a sharded time series collection.使用分片时间序列集合时,不能修改分片时间序列集合的granularity

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 Zones分片区

MongoDB does not support creating zones for sharded time series collections.MongoDB不支持为分片时间序列集合创建区域。

Shard Keys分片键

When sharding time series collections, you can only specify the following fields in the shard key:对时间序列集合进行分片时,只能在分片键中指定以下字段:

  • The metaField
  • Sub-fields of metaFieldmetaField的子字段
  • The timeField

You may specify combinations of these fields in the shard key. 您可以在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:要了解如何最好地选择分片键,请参阅:

Aggregation $out and $merge聚合$out$merge

The aggregation pipeline stages $out and $merge can't output to time series collections.聚合管道阶段$out$merge无法输出到时间序列集合

Transactions事务

You can't write to time series collections in transactions.无法在事务中写入时间序列集合

Note注意

Reads from time series collections are supported in transactions.事务中支持从时间序列集合读取数据。

Change Streams更改流

Change streams are not supported for time series collections.时间序列集合不支持更改流

Database Triggers数据库触发器

Database Triggers are not supported for time series collections.时间序列集合不支持数据库触发器

GraphQL API

GraphQL API is not supported for time series collections.时间序列集合不支持GraphQL API

Atlas Search

Atlas Search is not supported for time series collections.时间序列集合不支持Atlas搜索

Realm Sync

Realm Sync is not supported for time series collections.时间序列集合不支持Realm Sync

←  Time Series CollectionsSet up Automatic Removal for Time Series Collections (TTL) →