문서 메뉴
문서 홈
/ / /
Java 동기화
/

Time Series 컬렉션

이 페이지의 내용

  • 개요
  • Time Series 컬렉션 만들기
  • 시계열 컬렉션 쿼리

이 가이드에서는 MongoDB의 시계열 컬렉션과 MongoDB Java 드라이버에서 시계열 컬렉션 과 상호 작용하는 방법에 대해 알아볼 수 있습니다.

Time series 컬렉션은 일정 기간 동안의 측정 시퀀스를 효율적으로 저장합니다. 시계열 데이터는 시간이 지남에 따라 수집된 모든 데이터, 측정값을 설명하는 메타데이터 및 측정 시간으로 구성됩니다.

예제
측정
메타 데이터
판매 데이터
수익
회사
감염률
감염자 수
위치

time series 컬렉션을 만들려면 다음 매개변수를 createCollection() 메서드:

  • 생성할 새 컬렉션의 이름

  • TimeSeriesOptions CreateCollectionOptions 에 컬렉션을 만들기 위한 객체

MongoDatabase database = mongoClient.getDatabase("fall_weather");
TimeSeriesOptions tsOptions = new TimeSeriesOptions("temperature");
CreateCollectionOptions collOptions = new CreateCollectionOptions().timeSeriesOptions(tsOptions);
database.createCollection("september2021", collOptions);

중요

MongoDB 5.0 이전 버전에서는 time series 컬렉션을 만들 수 없습니다.

컬렉션이 성공적으로 생성되었는지 확인하려면 "listCollections" 명령을 runCommand() 메서드.

Document commandResult = database.runCommand(new Document("listCollections", new BsonInt64(1)));
List<String> keys = Arrays.asList("cursor");
System.out.println("listCollections: " + commandResult.getEmbedded(keys, Document.class).toJson());

출력은 다음과 유사해야 합니다.

{
"id": <some number>,
"ns": "<db name>.$cmd.listCollections",
"firstBatch": [
{
"name": "<time series collection name>",
"type": "timeseries",
"options": {
"expireAfterSeconds": <some number>,
"timeseries": { ... }
},
...
},
...
]
}

Time Series 컬렉션에서 쿼리하려면 데이터를 검색 하고 집계할 때와 동일한 규칙을 사용합니다.

참고

기간 기능

MongoDB 버전 5.0 은(는) 집계 파이프라인에 창 함수를 도입합니다. 윈도우 함수를 사용하여 연속된 Time Series 데이터 범위에 대한 작업을 수행할 수 있습니다. 자세한 내용은 애그리게이션 빌더 가이드를 참조하세요.

돌아가기

사용 중 암호화