Docs Menu

시계열 데이터의 세분성 설정

Time Series 컬렉션을 만들면 MongoDB는 자동으로 system.buckets 시스템 컬렉션을 만들고 수신 Time Series 데이터를 버킷으로 그룹화합니다. 세분성을 설정하면 데이터 수집 속도에 따라 데이터가 버킷되는 빈도를 제어할 수 있습니다.

MongoDB 6.3부터 사용자 지정 버킷 매개변수 bucketMaxSpanSecondsbucketRoundingSeconds를 사용하여 버킷 경계를 지정하고 Time Series 데이터의 버킷 방식을 보다 정확하게 제어할 수 있습니다.

버케팅에 대한 자세한 내용은 Time Series 데이터에 대한 정보를 참조하세요.

참고

컬렉션이 생성된 후 Time Series 컬렉션의 세분성을 변경하려면 MongoDB 5.0.1 이상을 실행해야 합니다. MongoDB 5.0 알려진 문제를 참조하세요.

현재 컬렉션 값을 조회하려면 listCollections 명령을 사용합니다.

db.runCommand( { listCollections: 1 } )

Time Series 컬렉션의 경우 출력에는 granularity, bucketMaxSpanSecondsbucketRoundingSeconds 매개변수(있는 경우)가 포함됩니다.

{
cursor: {
id: <number>,
ns: 'test.$cmd.listCollections',
firstBatch: [
{
name: <string>,
type: 'timeseries',
options: {
expireAfterSeconds: <number>,
timeseries: {
timeField: <string>,
metaField: <string>,
granularity: <string>,
bucketMaxSpanSeconds: <number>,
bucketRoundingSeconds: <number>
}
},
...
},
...
]
}
}

다음 예시에서는 weather24h 컬렉션의 granularityminutes로 설정합니다.

db.createCollection(
"weather24h",
{
timeseries: {
timeField: "timestamp",
metaField: "metadata",
granularity: "minutes"
},
expireAfterSeconds: 86400
}
)

다음도 참조하세요.

MongoDB 6.3 이상에서는 granularity 대신 사용자 지정 버킷 매개변수 두 개 를 사용하여 버킷 경계를 수동으로 설정할 수 있습니다. 자정부터 4시간마다와 같이 고정된 시간 간격에 대해 데이터를 쿼리하려는 경우 이 방법을 고려합니다. 해당 기간 사이에 버킷이 겹치지 않도록 하면 높은 쿼리 볼륨과 insert 작업에 최적화됩니다.

사용자 지정 버킷 매개 변수를 사용하려면 두 매개 변수를 모두 같은 값으로 설정하고 granularity를 설정하지 마세요.

  • bucketMaxSpanSeconds은(는) 같은 버킷의 타임스탬프 사이의 최대 시간을 설정합니다. 가능한 값은 1-31536000입니다.

  • bucketRoundingSeconds은(는) 새 버킷의 시작 타임스탬프를 결정하는 시간 간격을 설정합니다. 문서에 새 버킷이 필요한 경우 MongoDB는 문서의 타임스탬프 값을 이 간격으로 반올림하여 버킷의 최소 시간을 설정합니다.

기상 관측소 예시에서 4시간마다 요약 보고서를 생성하는 경우 "minutes"granularity를 사용하는 대신 사용자 지정 버킷팅 매개변수를 14,400초로 설정하여 버킷팅을 조정할 수 있습니다.

db.createCollection(
"weather24h",
{
timeseries: {
timeField: "timestamp",
metaField: "metadata",
bucketMaxSpanSeconds: 14400,
bucketRoundingSeconds: 14400
}
}
)

시간이 2023-03-27T16:24:35Z인 문서가 기존 버킷에 맞지 않는 경우, MongoDB는 최소 시간이 2023-03-27T16:00:00Z이고 최대 시간이 2023-03-27T19:59:59Z인 새 버킷을 생성합니다.

collMod 명령을 사용하여 더 짧은 시간 단위에서 더 긴 시간 단위로 timeseries.granularity를 늘릴 수 있습니다.

db.runCommand( {
collMod: "weather24h",
timeseries: { granularity: "seconds" | "minutes" | "hours" }
} )

granularity 대신 사용자 지정 버킷팅 매개변수 bucketRoundingSecondsbucketMaxSpanSeconds를 사용하는 경우 collMod 명령에 두 사용자 지정 매개변수를 모두 포함하고 동일한 값으로 설정합니다.

db.runCommand( {
collMod: "weather24h",
timeseries: {
bucketRoundingSeconds: 86400,
bucketMaxSpanSeconds: 86400
}
} )

세분화 간격이나 사용자 지정 버킷팅 값은 줄일 수 없습니다.

참고

샤드 time series 컬렉션의 세분성을 수정하려면 MongoDB 6.0 이상을 실행해야 합니다.