# MongoServerError：时间序列桶最大大小超出：ID为'...'的桶包含超过1000个测量值

- **ID:** `mongodb/timeseries-bucket-max-size-exceeded`
- **领域:** mongodb
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

由于具有相同元字段的高频写入，单个时间序列桶收集了超过默认1000个测量值，超出了桶的最大测量限制。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| mongodb 6.0 | active | — | — |
| mongodb 7.0 | active | — | — |
| mongodb 8.0 | active | — | — |

## 解决方案

1. ```
   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.
   ```
2. ```
   Increase the bucket max size parameter: `db.adminCommand({ setParameter: 1, timeseriesBucketMaxCount: 2000 })` to allow up to 2000 measurements per bucket.
   ```
3. ```
   Use the `granularity` option to control bucket time range: set `granularity: 'seconds'` to limit bucket to 1-second intervals, reducing measurement count per bucket.
   ```

## 无效尝试

- **** — The bucket limit is enforced by the storage engine; recreating with the same schema does not change the behavior, and the error will recur. (90% 失败率)
- **** — Directly modifying internal bucket collections can corrupt the time series data and is not supported by MongoDB; it may cause query failures. (95% 失败率)
- **** — While this might reduce bucket size, it increases latency and reduces throughput; it does not fix the root cause of meta field overlap. (65% 失败率)
