@@ -82,6 +82,10 @@ class CreateCollection implements Executable
8282 * This is not supported for server versions < 3.4 and will result in an
8383 * exception at execution time if used.
8484 *
85+ * * expireAfterSeconds: The TTL for documents in time series collections.
86+ *
87+ * This is not supported for servers versions < 5.0.
88+ *
8589 * * flags (integer): Options for the MMAPv1 storage engine only. Must be a
8690 * bitwise combination CreateCollection::USE_POWER_OF_2_SIZES and
8791 * CreateCollection::NO_PADDING. The default is
@@ -104,6 +108,10 @@ class CreateCollection implements Executable
104108 *
105109 * * storageEngine (document): Storage engine options.
106110 *
111+ * * timeseries (document): Options for time series collections.
112+ *
113+ * This is not supported for servers versions < 5.0.
114+ *
107115 * * typeMap (array): Type map for BSON deserialization. This will only be
108116 * used for the returned command result document.
109117 *
@@ -139,6 +147,10 @@ public function __construct($databaseName, $collectionName, array $options = [])
139147 throw InvalidArgumentException::invalidType ('"collation" option ' , $ options ['collation ' ], 'array or object ' );
140148 }
141149
150+ if (isset ($ options ['expireAfterSeconds ' ]) && ! is_integer ($ options ['expireAfterSeconds ' ])) {
151+ throw InvalidArgumentException::invalidType ('"expireAfterSeconds" option ' , $ options ['expireAfterSeconds ' ], 'integer ' );
152+ }
153+
142154 if (isset ($ options ['flags ' ]) && ! is_integer ($ options ['flags ' ])) {
143155 throw InvalidArgumentException::invalidType ('"flags" option ' , $ options ['flags ' ], 'integer ' );
144156 }
@@ -167,6 +179,10 @@ public function __construct($databaseName, $collectionName, array $options = [])
167179 throw InvalidArgumentException::invalidType ('"storageEngine" option ' , $ options ['storageEngine ' ], 'array or object ' );
168180 }
169181
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+
170186 if (isset ($ options ['typeMap ' ]) && ! is_array ($ options ['typeMap ' ])) {
171187 throw InvalidArgumentException::invalidType ('"typeMap" option ' , $ options ['typeMap ' ], 'array ' );
172188 }
@@ -237,13 +253,13 @@ private function createCommand()
237253 {
238254 $ cmd = ['create ' => $ this ->collectionName ];
239255
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 ) {
241257 if (isset ($ this ->options [$ option ])) {
242258 $ cmd [$ option ] = $ this ->options [$ option ];
243259 }
244260 }
245261
246- foreach (['collation ' , 'indexOptionDefaults ' , 'storageEngine ' , 'validator ' ] as $ option ) {
262+ foreach (['collation ' , 'indexOptionDefaults ' , 'storageEngine ' , 'timeseries ' , ' validator ' ] as $ option ) {
247263 if (isset ($ this ->options [$ option ])) {
248264 $ cmd [$ option ] = (object ) $ this ->options [$ option ];
249265 }
0 commit comments