Unverified Commit 1af82a40 authored by Katherine Walker's avatar Katherine Walker Committed by GitHub

PHPLIB-254 Support maxTimeMS option for CreateIndexes operation (#431)

* PHPLIB-254 Support maxTimeMS option for CreateIndexes operation
parent dcd6e841
...@@ -41,6 +41,10 @@ interface: phpmethod ...@@ -41,6 +41,10 @@ interface: phpmethod
operation: ~ operation: ~
optional: true optional: true
--- ---
source:
file: apiargs-common-option.yaml
ref: maxTimeMS
---
arg_name: option arg_name: option
name: name name: name
type: string type: string
......
source:
file: apiargs-common-option.yaml
ref: maxTimeMS
---
source: source:
file: apiargs-MongoDBCollection-common-option.yaml file: apiargs-MongoDBCollection-common-option.yaml
ref: writeConcern ref: writeConcern
......
...@@ -282,8 +282,8 @@ class Collection ...@@ -282,8 +282,8 @@ class Collection
*/ */
public function createIndex($key, array $options = []) public function createIndex($key, array $options = [])
{ {
$indexOptions = array_diff_key($options, ['writeConcern' => 1]); $indexOptions = array_diff_key($options, ['maxTimeMS' => 1, 'writeConcern' => 1]);
$commandOptions = array_intersect_key($options, ['writeConcern' => 1]); $commandOptions = array_intersect_key($options, ['maxTimeMS' => 1, 'writeConcern' => 1]);
return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions)); return current($this->createIndexes([['key' => $key] + $indexOptions], $commandOptions));
} }
......
...@@ -51,6 +51,9 @@ class CreateIndexes implements Executable ...@@ -51,6 +51,9 @@ class CreateIndexes implements Executable
* *
* Supported options: * Supported options:
* *
* * maxTimeMS (integer): The maximum amount of time to allow the query to
* run.
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern. * * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
* *
* This is not supported for server versions < 3.4 and will result in an * This is not supported for server versions < 3.4 and will result in an
...@@ -92,6 +95,10 @@ class CreateIndexes implements Executable ...@@ -92,6 +95,10 @@ class CreateIndexes implements Executable
$expectedIndex += 1; $expectedIndex += 1;
} }
if (isset($options['maxTimeMS']) && !is_integer($options['maxTimeMS'])) {
throw InvalidArgumentException::invalidType('"maxTimeMS" option', $options['maxTimeMS'], 'integer');
}
if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) { if (isset($options['writeConcern']) && ! $options['writeConcern'] instanceof WriteConcern) {
throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern'); throw InvalidArgumentException::invalidType('"writeConcern" option', $options['writeConcern'], 'MongoDB\Driver\WriteConcern');
} }
...@@ -150,6 +157,10 @@ class CreateIndexes implements Executable ...@@ -150,6 +157,10 @@ class CreateIndexes implements Executable
'indexes' => $this->indexes, 'indexes' => $this->indexes,
]; ];
if (isset($this->options['maxTimeMS'])) {
$cmd['maxTimeMS'] = $this->options['maxTimeMS'];
}
if (isset($this->options['writeConcern'])) { if (isset($this->options['writeConcern'])) {
$cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']); $cmd['writeConcern'] = \MongoDB\write_concern_as_document($this->options['writeConcern']);
} }
......
...@@ -28,6 +28,10 @@ class CreateIndexesTest extends TestCase ...@@ -28,6 +28,10 @@ class CreateIndexesTest extends TestCase
{ {
$options = []; $options = [];
foreach ($this->getInvalidIntegerValues() as $value) {
$options[][] = ['maxTimeMS' => $value];
}
foreach ($this->getInvalidWriteConcernValues() as $value) { foreach ($this->getInvalidWriteConcernValues() as $value) {
$options[][] = ['writeConcern' => $value]; $options[][] = ['writeConcern' => $value];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment