MongoServerError:时间序列桶最大大小超出:ID为'...'的桶包含超过1000个测量值
MongoServerError: time series bucket max size exceeded: bucket with id '...' has more than 1000 measurements
ID: mongodb/timeseries-bucket-max-size-exceeded
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| mongodb 6.0 | active | — | — | — |
| mongodb 7.0 | active | — | — | — |
| mongodb 8.0 | active | — | — | — |
根因分析
由于具有相同元字段的高频写入,单个时间序列桶收集了超过默认1000个测量值,超出了桶的最大测量限制。
English
A single time series bucket collected more than the default 1000 measurements due to high-frequency writes with identical meta fields, exceeding the bucket's maximum measurement limit.
官方文档
https://www.mongodb.com/docs/manual/core/timeseries-collections/#bucket-limits解决方案
-
Add a unique identifier (e.g., device ID + timestamp prefix) to the meta field to ensure finer bucket granularity: `db.createCollection('sensor_data', { timeseries: { timeField: 'timestamp', metaField: 'metadata', granularity: 'seconds' } })` with `metadata: { deviceId: 'sensor1', batch: Date.now() }` in inserts. -
Increase the bucket max size parameter: `db.adminCommand({ setParameter: 1, timeseriesBucketMaxCount: 2000 })` to allow up to 2000 measurements per bucket. -
Use the `granularity` option to control bucket time range: set `granularity: 'seconds'` to limit bucket to 1-second intervals, reducing measurement count per bucket.
无效尝试
常见但无效的做法:
-
90% 失败
The bucket limit is enforced by the storage engine; recreating with the same schema does not change the behavior, and the error will recur.
-
95% 失败
Directly modifying internal bucket collections can corrupt the time series data and is not supported by MongoDB; it may cause query failures.
-
65% 失败
While this might reduce bucket size, it increases latency and reduces throughput; it does not fix the root cause of meta field overlap.