|
5 | 5 | use MongoDB\Driver\Command; |
6 | 6 | use MongoDB\Driver\Server; |
7 | 7 | use MongoDB\Exception\InvalidArgumentException; |
8 | | -use MongoDB\Exception\UnexpectedTypeException; |
9 | | -use MongoDB\Model\IndexInput; |
| 8 | +use MongoDB\Exception\InvalidArgumentTypeException; |
10 | 9 |
|
11 | 10 | /** |
12 | 11 | * Operation for the create command. |
@@ -40,6 +39,9 @@ class CreateCollection implements Executable |
40 | 39 | * bitwise combination USE_POWER_OF_2_SIZES and NO_PADDING. The default |
41 | 40 | * is USE_POWER_OF_2_SIZES. |
42 | 41 | * |
| 42 | + * * indexOptionDefaults (document): Default configuration for indexes when |
| 43 | + * creating the collection. |
| 44 | + * |
43 | 45 | * * max (integer): The maximum number of documents allowed in the capped |
44 | 46 | * collection. The size option takes precedence over this limit. |
45 | 47 | * |
@@ -70,6 +72,10 @@ public function __construct($databaseName, $collectionName, array $options = []) |
70 | 72 | throw new InvalidArgumentTypeException('"flags" option', $options['flags'], 'integer'); |
71 | 73 | } |
72 | 74 |
|
| 75 | + if (isset($options['indexOptionDefaults']) && ! is_array($options['indexOptionDefaults']) && ! is_object($options['indexOptionDefaults'])) { |
| 76 | + throw new InvalidArgumentTypeException('"indexOptionDefaults" option', $options['indexOptionDefaults'], 'array or object'); |
| 77 | + } |
| 78 | + |
73 | 79 | if (isset($options['max']) && ! is_integer($options['max'])) { |
74 | 80 | throw new InvalidArgumentTypeException('"max" option', $options['max'], 'integer'); |
75 | 81 | } |
@@ -120,6 +126,10 @@ private function createCommand() |
120 | 126 | } |
121 | 127 | } |
122 | 128 |
|
| 129 | + if ( ! empty($this->options['indexOptionDefaults'])) { |
| 130 | + $cmd['indexOptionDefaults'] = (object) $this->options['indexOptionDefaults']; |
| 131 | + } |
| 132 | + |
123 | 133 | if ( ! empty($this->options['storageEngine'])) { |
124 | 134 | $cmd['storageEngine'] = (object) $this->options['storageEngine']; |
125 | 135 | } |
|
0 commit comments