AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.

Time Series 컬렉션

이 가이드에서는 MongoDB의 time series 컬렉션에 대해 알아보고, MongoDB Go 드라이버에서 time series 컬렉션과 상호 작용하는 방법을 알아봅니다.

time series 컬렉션은 일정 기간 동안의 측정 시퀀스를 효율적으로 저장합니다. 이 collection은 다음 정보가 포함된 time-series 데이터로 구성됩니다.

  • 시간 경과에 따라 수집된 데이터

  • 측정값을 설명하는 메타데이터

  • 측정 날짜

예시
측정
Metadata

판매 데이터

수익

회사

감염률

감염자 수

위치

중요

Time series 컬렉션에는 MongoDB 5.0 이상이 필요합니다.

time series 컬렉션을 만들려면 CreateCollection() 메서드에 다음 매개변수를 전달합니다.

  • 생성할 새 컬렉션의 이름

  • 최소한 시간 필드를 지정하는 TimeSeriesOptions 객체

다음 예에서는 temperature 를 시간 필드로 사용하여 db 데이터베이스에 march2022 time series 컬렉션을 만듭니다.

db := client.Database("db") // Creates a time series collection that stores "temperature" values over timetso := options.TimeSeries().SetTimeField("temperature")opts := options.CreateCollection().SetTimeSeriesOptions(tso) db.CreateCollection(context.TODO(), "march2022", opts)

컬렉션을 생성했는지 확인하려면 RunCommand() 메서드에 "listCollections" 명령을 보냅니다.

package main import ( "context" "encoding/json" "fmt" "log" "os" "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/mongo" "go.mongodb.org/mongo-driver/v2/mongo/options") func main() { var uri string if uri = os.Getenv("MONGODB_URI"); uri == "" { log.Fatal("You must set your 'MONGODB_URI' environment variable. See\n\t https://www.mongodb.com/ko-kr/docs/drivers/go/current/usage-examples/") } client, err := mongo.Connect(options.Client().ApplyURI(uri)) if err != nil { panic(err) } defer client.Disconnect(context.TODO()) db := client.Database("myDB") // Creates a command to list collections command := bson.D{{"listCollections", 1}} var result bson.M // Runs the command on the database commandErr := db.RunCommand(context.TODO(), command).Decode(&result) if commandErr != nil { panic(commandErr) } // Prints the command results output, outputErr := json.MarshalIndent(result, "", " ") if outputErr != nil { panic(outputErr) } fmt.Printf("%s\n", output)}

time series 컬렉션을 쿼리하려면 데이터 검색 및 집계와 동일한 규칙을 사용합니다.

언급된 작업에 대해 자세히 알아보려면 다음 가이드를 참조하세요.

이 가이드에서 설명하는 메서드나 유형에 대해 자세히 알아보려면 다음 API 설명서를 참조하세요.