Docs Menu
Docs Home
/
데이터베이스 매뉴얼
/ /

Time Series 컬렉션 샤드

버전 5.1에 추가되었습니다.

이 튜토리얼을 사용하여 새 time series 컬렉션 또는 기존 time series을 샤드할 수 있습니다.

중요

이 튜토리얼을 완료하기 전에 time series 컬렉션에 대한 샤딩 제한 사항을 검토하세요.

time series 컬렉션을 샤딩하려면 샤딩된 클러스터를 배포하여 time series 컬렉션이 포함된 데이터베이스를 호스팅해야 합니다.

참고

MongoDB 8.0.10부터 time series 컬렉션 리샤딩할 수 있습니다. time series 컬렉션 의 모든 샤드는 리샤딩하려면 버전 8.0.10 이상 실행 해야 합니다.

1

mongosh 를 샤드 클러스터의 mongos 에 연결합니다. mongos 이(가) 실행 중인 hostport 을(를) 지정합니다.

mongosh --host <hostname> --port <port>
2

sh.status() (을)를 실행하여 데이터베이스에서 샤드가 활성화되었는지 확인합니다.

sh.status()

이 명령은 샤딩 정보를 반환합니다.

--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
...
3

timeseries 옵션과 함께 shardCollection() 메서드를 사용합니다.

예를 들면 다음과 같습니다.

sh.shardCollection(
"test.weather",
{ "metadata.sensorId": 1 },
{
timeseries: {
timeField: "timestamp",
metaField: "metadata",
granularity: "hours"
}
}
)

이 예에서 sh.shardCollection():

  • test 데이터베이스에 이름이 weather인 새 time series 컬렉션을 샤딩합니다.

  • metadata.sensorId 필드를 샤드 키로 지정합니다.

  • granularity 시간을 지정합니다.

다음 문서에는 컬렉션에 적합한 메타데이터가 포함되어 있습니다.

db.weather.insertOne( {
"metadata": { "sensorId": 5578, "type": "temperature" },
"timestamp": ISODate("2021-05-18T00:00:00.000Z"),
"temp": 12
} )
1

mongosh를 샤딩된 클러스터의 mongos에 연결합니다. mongos가 실행 중인 hostport를 지정합니다.

mongosh --host <hostname> --port <port>
2

sh.status() (을)를 실행하여 데이터베이스에서 샤드가 활성화되었는지 확인합니다.

sh.status()

이 명령은 샤딩 정보를 반환합니다.

--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
...
3

샤드 키를 지원하는 인덱스를 만들어 컬렉션에서 샤드를 사용하도록 설정합니다.

다음 속성을 가진 time series 컬렉션을 고려합니다.

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

컬렉션의 샘플 문서가 다음과 유사합니다.

db.deliverySensor.insertOne( {
"metadata": { "location": "USA", "vehicle": "truck" },
"timestamp": ISODate("2021-08-21T00:00:10.000Z"),
"speed": 50
} )

다음 명령어를 실행하여 metadata.location 필드에 해시된 인덱스를 생성합니다.

db.deliverySensor.createIndex( { "metadata.location" : "hashed" } )
4

shardCollection() 메서드를 사용하여 컬렉션을 샤드합니다.

이전 단계에서 설명한 deliverySensor 컬렉션을 샤드하려면 다음 명령을 실행합니다.

sh.shardCollection( "test.deliverySensor", { "metadata.location": "hashed" } )

이 예에서 sh.shardCollection():

  • test 데이터베이스에 이름이 deliverySensor인 기존 Time Series 컬렉션을 샤드합니다.

  • metadata.location 필드를 샤드 키로 지정합니다. location은 컬렉션의 metaField 하위 필드입니다.

sh.shardCollection()에 지정하는 컬렉션이 Time Series 컬렉션인 경우 time-series 옵션을 지정할 필요가 없습니다.

돌아가기

압축

이 페이지의 내용