@@ -21,6 +21,9 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
2121 /// decoded using this strategy.
2222 public var dateCodingStrategy : DateCodingStrategy ? = nil
2323
24+ /// Number of seconds after which old time series data should be deleted.
25+ public var expireAfterSeconds : Int ?
26+
2427 /// Specify a default configuration for indexes created on this collection.
2528 public var indexOptionDefaults : BSONDocument ?
2629
@@ -37,6 +40,9 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
3740 /// Specifies storage engine configuration for this collection.
3841 public var storageEngine : BSONDocument ?
3942
43+ /// The options used for creating a time series collection. This feature is only available on MongoDB 5.0+.
44+ public var timeseries : TimeseriesOptions ?
45+
4046 /// Specifies the `UUIDCodingStrategy` to use for BSON encoding/decoding operations performed by this collection.
4147 /// It is the responsibility of the user to ensure that any `UUID`s already stored in this collection can be
4248 /// decoded using this strategy.
@@ -63,7 +69,7 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
6369
6470 private enum CodingKeys : String , CodingKey {
6571 case capped, size, max, storageEngine, validator, validationLevel, validationAction,
66- indexOptionDefaults, viewOn, pipeline, collation, writeConcern
72+ indexOptionDefaults, viewOn, pipeline, collation, writeConcern, timeseries , expireAfterSeconds
6773 }
6874
6975 /// Convenience initializer allowing any/all parameters to be omitted or optional.
@@ -72,11 +78,13 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
7278 collation: BSONDocument ? = nil ,
7379 dataCodingStrategy: DataCodingStrategy ? = nil ,
7480 dateCodingStrategy: DateCodingStrategy ? = nil ,
81+ expireAfterSeconds: Int ? = nil ,
7582 indexOptionDefaults: BSONDocument ? = nil ,
7683 max: Int ? = nil ,
7784 pipeline: [ BSONDocument ] ? = nil ,
7885 size: Int ? = nil ,
7986 storageEngine: BSONDocument ? = nil ,
87+ timeseries: TimeseriesOptions ? = nil ,
8088 uuidCodingStrategy: UUIDCodingStrategy ? = nil ,
8189 validationAction: String ? = nil ,
8290 validationLevel: String ? = nil ,
@@ -99,6 +107,45 @@ public struct CreateCollectionOptions: Codable, CodingStrategyProvider {
99107 self . validator = validator
100108 self . viewOn = viewOn
101109 self . writeConcern = writeConcern
110+ self . timeseries = timeseries
111+ self . expireAfterSeconds = expireAfterSeconds
112+ }
113+ }
114+
115+ /// The options to use when creating a time series collection.
116+ public struct TimeseriesOptions : Codable {
117+ /// Name of the top-level field to be used for time. Inserted documents must have this field, and the field must
118+ /// be of the BSON UTC datetime type.
119+ public var timeField : String
120+
121+ /// Name of the top-level field describing the series. This field is used to group related data and may be of any
122+ /// BSON type except array. This name must not be the same as the `timeField` or `_id`.
123+ public var metaField : String ?
124+
125+ /// The units used to describe the expected interval between subsequent measurements for a time series
126+ /// collection. Defaults to `Granularity.seconds` if unset.
127+ public var granularity : Granularity ?
128+
129+ /// The units used to describe the expected interval between subsequent measurements for a time series collection.
130+ public struct Granularity : RawRepresentable , Codable {
131+ public static let seconds = Granularity ( " seconds " )
132+ public static let minutes = Granularity ( " minutes " )
133+ public static let hours = Granularity ( " hours " )
134+
135+ /// For an unknown value. For forwards compatibility, no error will be thrown when an unknown value is
136+ /// provided.
137+ public static func other( _ value: String ) -> Granularity {
138+ Granularity ( value)
139+ }
140+
141+ public var rawValue : String
142+
143+ public init ? ( rawValue: String ) { self . rawValue = rawValue }
144+ internal init ( _ value: String ) { self . rawValue = value }
145+ }
146+
147+ private enum CodingKeys : String , CodingKey {
148+ case timeField, metaField, granularity
102149 }
103150}
104151
0 commit comments