@@ -82,6 +82,10 @@ class CreateCollection implements Executable
82
82
* This is not supported for server versions < 3.4 and will result in an
83
83
* exception at execution time if used.
84
84
*
85
+ * * expireAfterSeconds: The TTL for documents in time series collections.
86
+ *
87
+ * This is not supported for servers versions < 5.0.
88
+ *
85
89
* * flags (integer): Options for the MMAPv1 storage engine only. Must be a
86
90
* bitwise combination CreateCollection::USE_POWER_OF_2_SIZES and
87
91
* CreateCollection::NO_PADDING. The default is
@@ -104,6 +108,10 @@ class CreateCollection implements Executable
104
108
*
105
109
* * storageEngine (document): Storage engine options.
106
110
*
111
+ * * timeseries (document): Options for time series collections.
112
+ *
113
+ * This is not supported for servers versions < 5.0.
114
+ *
107
115
* * typeMap (array): Type map for BSON deserialization. This will only be
108
116
* used for the returned command result document.
109
117
*
@@ -139,6 +147,10 @@ public function __construct($databaseName, $collectionName, array $options = [])
139
147
throw InvalidArgumentException::invalidType ('"collation" option ' , $ options ['collation ' ], 'array or object ' );
140
148
}
141
149
150
+ if (isset ($ options ['expireAfterSeconds ' ]) && ! is_integer ($ options ['expireAfterSeconds ' ])) {
151
+ throw InvalidArgumentException::invalidType ('"expireAfterSeconds" option ' , $ options ['expireAfterSeconds ' ], 'integer ' );
152
+ }
153
+
142
154
if (isset ($ options ['flags ' ]) && ! is_integer ($ options ['flags ' ])) {
143
155
throw InvalidArgumentException::invalidType ('"flags" option ' , $ options ['flags ' ], 'integer ' );
144
156
}
@@ -167,6 +179,10 @@ public function __construct($databaseName, $collectionName, array $options = [])
167
179
throw InvalidArgumentException::invalidType ('"storageEngine" option ' , $ options ['storageEngine ' ], 'array or object ' );
168
180
}
169
181
182
+ if (isset ($ options ['timeseries ' ]) && ! is_array ($ options ['timeseries ' ]) && ! is_object ($ options ['timeseries ' ])) {
183
+ throw InvalidArgumentException::invalidType ('"timeseries" option ' , $ options ['timeseries ' ], ['array ' , 'object ' ]);
184
+ }
185
+
170
186
if (isset ($ options ['typeMap ' ]) && ! is_array ($ options ['typeMap ' ])) {
171
187
throw InvalidArgumentException::invalidType ('"typeMap" option ' , $ options ['typeMap ' ], 'array ' );
172
188
}
@@ -237,13 +253,13 @@ private function createCommand()
237
253
{
238
254
$ cmd = ['create ' => $ this ->collectionName ];
239
255
240
- foreach (['autoIndexId ' , 'capped ' , 'flags ' , 'max ' , 'maxTimeMS ' , 'size ' , 'validationAction ' , 'validationLevel ' ] as $ option ) {
256
+ foreach (['autoIndexId ' , 'capped ' , 'expireAfterSeconds ' , ' flags ' , 'max ' , 'maxTimeMS ' , 'size ' , 'validationAction ' , 'validationLevel ' ] as $ option ) {
241
257
if (isset ($ this ->options [$ option ])) {
242
258
$ cmd [$ option ] = $ this ->options [$ option ];
243
259
}
244
260
}
245
261
246
- foreach (['collation ' , 'indexOptionDefaults ' , 'storageEngine ' , 'validator ' ] as $ option ) {
262
+ foreach (['collation ' , 'indexOptionDefaults ' , 'storageEngine ' , 'timeseries ' , ' validator ' ] as $ option ) {
247
263
if (isset ($ this ->options [$ option ])) {
248
264
$ cmd [$ option ] = (object ) $ this ->options [$ option ];
249
265
}
0 commit comments