mongodb data_error ai_generated true

MongoServerError: time series bucket max size exceeded: bucket with id '...' has more than 1000 measurements

ID: mongodb/timeseries-bucket-max-size-exceeded

Also available as: JSON · Markdown · 中文
82%Fix Rate
86%Confidence
1Evidence
2024-03-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
mongodb 6.0 active
mongodb 7.0 active
mongodb 8.0 active

Root Cause

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.

generic

中文

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

Official Documentation

https://www.mongodb.com/docs/manual/core/timeseries-collections/#bucket-limits

Workarounds

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

中文步骤

  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.

Dead Ends

Common approaches that don't work:

  1. 90% fail

    The bucket limit is enforced by the storage engine; recreating with the same schema does not change the behavior, and the error will recur.

  2. 95% fail

    Directly modifying internal bucket collections can corrupt the time series data and is not supported by MongoDB; it may cause query failures.

  3. 65% fail

    While this might reduce bucket size, it increases latency and reduces throughput; it does not fix the root cause of meta field overlap.