Skip to content

Commit d8c5d09

Browse files
authored
PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478)
* PHPLIB-1546: Remove CreateCollection flags option and related constants * PHPLIB-1159: Remove CreateCollection autoIndexId option
1 parent 25a196e commit d8c5d09

File tree

4 files changed

+6
-46
lines changed

4 files changed

+6
-46
lines changed

Diff for: UPGRADE-2.0.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ UPGRADE FROM 1.x to 2.0
2222
* `MongoDB\Model\IndexInfoIterator`
2323
* `MongoDB\Model\IndexInfoIteratorIterator`
2424
* `MongoDB\Operation\Executable`
25+
* The `flags` and `autoIndexId` options for
26+
`MongoDB\Database::createCollection()` have been removed. Additionally, the
27+
`USE_POWER_OF_2_SIZES` and `NO_PADDING` constants in
28+
`MongoDB\Operation\CreateCollection` have been removed.
2529

2630
Operations with no result
2731
-------------------------

Diff for: src/Operation/CreateCollection.php

+1-32
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
use function is_string;
3131
use function MongoDB\is_document;
3232
use function MongoDB\is_pipeline;
33-
use function trigger_error;
34-
35-
use const E_USER_DEPRECATED;
3633

3734
/**
3835
* Operation for the create command.
@@ -42,22 +39,11 @@
4239
*/
4340
final class CreateCollection
4441
{
45-
public const USE_POWER_OF_2_SIZES = 1;
46-
public const NO_PADDING = 2;
47-
4842
/**
4943
* Constructs a create command.
5044
*
5145
* Supported options:
5246
*
53-
* * autoIndexId (boolean): Specify false to disable the automatic creation
54-
* of an index on the _id field. For replica sets, this option cannot be
55-
* false. The default is true.
56-
*
57-
* This option has been deprecated since MongoDB 3.2. As of MongoDB 4.0,
58-
* this option cannot be false when creating a replicated collection
59-
* (i.e. a collection outside of the local database in any mongod mode).
60-
*
6147
* * capped (boolean): Specify true to create a capped collection. If set,
6248
* the size option must also be specified. The default is false.
6349
*
@@ -83,11 +69,6 @@ final class CreateCollection
8369
*
8470
* This is not supported for servers versions < 5.0.
8571
*
86-
* * flags (integer): Options for the MMAPv1 storage engine only. Must be a
87-
* bitwise combination CreateCollection::USE_POWER_OF_2_SIZES and
88-
* CreateCollection::NO_PADDING. The default is
89-
* CreateCollection::USE_POWER_OF_2_SIZES.
90-
*
9172
* * indexOptionDefaults (document): Default configuration for indexes when
9273
* creating the collection.
9374
*
@@ -131,10 +112,6 @@ final class CreateCollection
131112
*/
132113
public function __construct(private string $databaseName, private string $collectionName, private array $options = [])
133114
{
134-
if (isset($this->options['autoIndexId']) && ! is_bool($this->options['autoIndexId'])) {
135-
throw InvalidArgumentException::invalidType('"autoIndexId" option', $this->options['autoIndexId'], 'boolean');
136-
}
137-
138115
if (isset($this->options['capped']) && ! is_bool($this->options['capped'])) {
139116
throw InvalidArgumentException::invalidType('"capped" option', $this->options['capped'], 'boolean');
140117
}
@@ -159,10 +136,6 @@ public function __construct(private string $databaseName, private string $collec
159136
throw InvalidArgumentException::invalidType('"expireAfterSeconds" option', $this->options['expireAfterSeconds'], 'integer');
160137
}
161138

162-
if (isset($this->options['flags']) && ! is_integer($this->options['flags'])) {
163-
throw InvalidArgumentException::invalidType('"flags" option', $this->options['flags'], 'integer');
164-
}
165-
166139
if (isset($this->options['indexOptionDefaults']) && ! is_document($this->options['indexOptionDefaults'])) {
167140
throw InvalidArgumentException::expectedDocumentType('"indexOptionDefaults" option', $this->options['indexOptionDefaults']);
168141
}
@@ -219,10 +192,6 @@ public function __construct(private string $databaseName, private string $collec
219192
unset($this->options['writeConcern']);
220193
}
221194

222-
if (isset($this->options['autoIndexId'])) {
223-
trigger_error('The "autoIndexId" option is deprecated and will be removed in version 2.0', E_USER_DEPRECATED);
224-
}
225-
226195
if (isset($this->options['pipeline']) && ! is_pipeline($this->options['pipeline'], true /* allowEmpty */)) {
227196
throw new InvalidArgumentException('"pipeline" option is not a valid aggregation pipeline');
228197
}
@@ -245,7 +214,7 @@ private function createCommand(): Command
245214
{
246215
$cmd = ['create' => $this->collectionName];
247216

248-
foreach (['autoIndexId', 'capped', 'comment', 'expireAfterSeconds', 'flags', 'max', 'maxTimeMS', 'pipeline', 'size', 'validationAction', 'validationLevel', 'viewOn'] as $option) {
217+
foreach (['capped', 'comment', 'expireAfterSeconds', 'max', 'maxTimeMS', 'pipeline', 'size', 'validationAction', 'validationLevel', 'viewOn'] as $option) {
249218
if (isset($this->options[$option])) {
250219
$cmd[$option] = $this->options[$option];
251220
}

Diff for: tests/Operation/CreateCollectionTest.php

-13
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,12 @@ public function testConstructorOptionTypeChecks(array $options): void
2525
public static function provideInvalidConstructorOptions()
2626
{
2727
return self::createOptionDataProvider([
28-
'autoIndexId' => self::getInvalidBooleanValues(),
2928
'capped' => self::getInvalidBooleanValues(),
3029
'changeStreamPreAndPostImages' => self::getInvalidDocumentValues(),
3130
'clusteredIndex' => self::getInvalidDocumentValues(),
3231
'collation' => self::getInvalidDocumentValues(),
3332
'encryptedFields' => self::getInvalidDocumentValues(),
3433
'expireAfterSeconds' => self::getInvalidIntegerValues(),
35-
'flags' => self::getInvalidIntegerValues(),
3634
'indexOptionDefaults' => self::getInvalidDocumentValues(),
3735
'max' => self::getInvalidIntegerValues(),
3836
'maxTimeMS' => self::getInvalidIntegerValues(),
@@ -48,15 +46,4 @@ public static function provideInvalidConstructorOptions()
4846
'writeConcern' => self::getInvalidWriteConcernValues(),
4947
]);
5048
}
51-
52-
public function testAutoIndexIdOptionIsDeprecated(): void
53-
{
54-
$this->assertDeprecated(function (): void {
55-
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['autoIndexId' => true]);
56-
});
57-
58-
$this->assertDeprecated(function (): void {
59-
new CreateCollection($this->getDatabaseName(), $this->getCollectionName(), ['autoIndexId' => false]);
60-
});
61-
}
6249
}

Diff for: tests/UnifiedSpecTests/Util.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ final class Util
7575
Database::class => [
7676
'aggregate' => ['pipeline', 'session', 'allowDiskUse', 'batchSize', 'bypassDocumentValidation', 'collation', 'comment', 'explain', 'hint', 'let', 'maxAwaitTimeMS', 'maxTimeMS'],
7777
'createChangeStream' => ['pipeline', 'session', 'fullDocument', 'resumeAfter', 'startAfter', 'startAtOperationTime', 'batchSize', 'collation', 'maxAwaitTimeMS', 'showExpandedEvents'],
78-
'createCollection' => ['collection', 'session', 'autoIndexId', 'capped', 'changeStreamPreAndPostImages', 'clusteredIndex', 'collation', 'expireAfterSeconds', 'flags', 'indexOptionDefaults', 'max', 'maxTimeMS', 'pipeline', 'size', 'storageEngine', 'timeseries', 'validationAction', 'validationLevel', 'validator', 'viewOn'],
78+
'createCollection' => ['collection', 'session', 'capped', 'changeStreamPreAndPostImages', 'clusteredIndex', 'collation', 'expireAfterSeconds', 'indexOptionDefaults', 'max', 'maxTimeMS', 'pipeline', 'size', 'storageEngine', 'timeseries', 'validationAction', 'validationLevel', 'validator', 'viewOn'],
7979
'dropCollection' => ['collection', 'session'],
8080
'listCollectionNames' => ['authorizedCollections', 'filter', 'maxTimeMS', 'session'],
8181
'listCollections' => ['authorizedCollections', 'filter', 'maxTimeMS', 'session'],

0 commit comments

Comments
 (0)