Skip to content

Commit 2a0ed75

Browse files
committed
PHPLIB-254 Support maxTimeMS option for CreateIndexes operation
1 parent d4583a9 commit 2a0ed75

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ public function count($filter = [], array $options = [])
282282
*/
283283
public function createIndex($key, array $options = [])
284284
{
285-
$indexOptions = array_diff_key($options, ['writeConcern' => 1]);
286-
$commandOptions = array_intersect_key($options, ['writeConcern' => 1]);
285+
$indexOptions = array_diff_key($options, ['maxTimeMS' => 1, 'writeConcern' => 1]);
286+
$commandOptions = array_intersect_key($options, ['maxTimeMS' => 1, 'writeConcern' => 1]);
287287

288288
return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions));
289289
}

src/Operation/CreateIndexes.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public function __construct($databaseName, $collectionName, array $indexes, arra
9292
$expectedIndex += 1;
9393
}
9494

95+
if (isset($options['maxTimeMS']) && !is_integer($options['maxTimeMS'])) {
96+
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
97+
}
98+
9599
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
96100
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
97101
}
@@ -150,6 +154,10 @@ private function executeCommand(Server $server)
150154
'indexes' => $this->indexes,
151155
];
152156

157+
if (isset($this->options['maxTimeMS'])) {
158+
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
159+
}
160+
153161
if (isset($this->options['writeConcern'])) {
154162
$cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']);
155163
}

0 commit comments

Comments
 (0)