Skip to content

Commit 1f7abd5

Browse files
committed
Add let and comment to explain delete
Separate Intentionally omitted option
1 parent 06234eb commit 1f7abd5

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

src/Operation/Delete.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,17 @@ public function execute(Server $server)
177177
*/
178178
public function getCommandDocument()
179179
{
180-
return ['delete' => $this->collectionName, 'deletes' => [['q' => $this->filter] + $this->createDeleteOptions()]];
180+
$cmd = ['delete' => $this->collectionName, 'deletes' => [['q' => $this->filter] + $this->createDeleteOptions()]];
181+
182+
if (isset($this->options['comment'])) {
183+
$cmd['comment'] = $this->options['comment'];
184+
}
185+
186+
if (isset($this->options['let'])) {
187+
$cmd['let'] = (object) $this->options['let'];
188+
}
189+
190+
return $cmd;
181191
}
182192

183193
/**

tests/Operation/DeleteTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace MongoDB\Tests\Operation;
99

10+
use MongoDB\Driver\WriteConcern;
1011
use MongoDB\Exception\InvalidArgumentException;
1112
use MongoDB\Operation\Delete;
1213
use TypeError;
@@ -71,10 +72,10 @@ public function testExplainableCommandDocument(): void
7172
$options = [
7273
'collation' => ['locale' => 'fr'],
7374
'hint' => '_id_',
74-
// Ignored options
7575
'let' => ['a' => 1],
76-
'ordered' => true,
7776
'comment' => 'explain me',
77+
// Intentionally omitted options
78+
'writeConcern' => new WriteConcern(0),
7879
];
7980
$operation = new Delete($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], 0, $options);
8081

@@ -88,6 +89,8 @@ public function testExplainableCommandDocument(): void
8889
'hint' => '_id_',
8990
],
9091
],
92+
'comment' => 'explain me',
93+
'let' => (object) ['a' => 1],
9194
];
9295
$this->assertEquals($expected, $operation->getCommandDocument());
9396
}

tests/Operation/DistinctTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use MongoDB\Driver\ReadConcern;
66
use MongoDB\Driver\ReadPreference;
7+
use MongoDB\Driver\WriteConcern;
78
use MongoDB\Exception\InvalidArgumentException;
89
use MongoDB\Operation\Distinct;
910

@@ -60,9 +61,10 @@ public function testExplainableCommandDocument(): void
6061
'collation' => ['locale' => 'fr'],
6162
'maxTimeMS' => 100,
6263
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
64+
'comment' => 'explain me',
65+
// Intentionally omitted options
6366
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
6467
'typeMap' => ['root' => 'array'],
65-
'comment' => 'explain me',
6668
];
6769
$operation = new Distinct($this->getDatabaseName(), $this->getCollectionName(), 'f', ['x' => 1], $options);
6870

tests/Operation/FindAndModifyTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ public function testExplainableCommandDocument(): void
9797
'maxTimeMS' => 100,
9898
'new' => true,
9999
'query' => ['y' => 2],
100-
'remove' => false,
101100
'sort' => ['x' => 1],
102-
'typeMap' => ['root' => 'array'],
103101
'update' => ['$set' => ['x' => 2]],
104102
'upsert' => true,
105103
'let' => ['a' => 3],
106-
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
104+
// Intentionally omitted options
105+
'remove' => false, // When "update" is set
106+
'typeMap' => ['root' => 'array'],
107+
'writeConcern' => new WriteConcern(0),
107108
];
108109
$operation = new FindAndModify($this->getDatabaseName(), $this->getCollectionName(), $options);
109110

tests/Operation/FindOneAndDeleteTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ public function testExplainableCommandDocument(): void
4040
'comment' => 'explain me',
4141
'hint' => '_id_',
4242
'maxTimeMS' => 100,
43-
'projection' => ['_id' => 0],
4443
'sort' => ['x' => 1],
4544
'let' => ['a' => 3],
45+
// Intentionally omitted options
46+
'projection' => ['_id' => 0],
4647
'typeMap' => ['root' => 'array'],
4748
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
4849
];

tests/Operation/FindOneAndReplaceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ public function testExplainableCommandDocument(): void
9494
'hint' => '_id_',
9595
'maxTimeMS' => 100,
9696
'projection' => ['_id' => 0],
97-
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
9897
'sort' => ['x' => 1],
99-
'typeMap' => ['root' => 'array'],
10098
'let' => ['a' => 3],
99+
// Intentionally omitted options
100+
'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER,
101+
'typeMap' => ['root' => 'array'],
101102
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
102103
];
103104
$operation = new FindOneAndReplace($this->getDatabaseName(), $this->getCollectionName(), ['y' => 2], ['y' => 3], $options);

tests/Operation/FindOneAndUpdateTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ public function testExplainableCommandDocument(): void
7676
'comment' => 'explain me',
7777
'hint' => '_id_',
7878
'maxTimeMS' => 100,
79-
'projection' => ['_id' => 0],
80-
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
8179
'sort' => ['x' => 1],
82-
'typeMap' => ['root' => 'array'],
8380
'upsert' => true,
8481
'let' => ['a' => 3],
82+
// Intentionally omitted options
83+
'projection' => ['_id' => 0],
84+
'returnDocument' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER,
85+
'typeMap' => ['root' => 'array'],
8586
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY),
8687
];
8788
$operation = new FindOneAndUpdate($this->getDatabaseName(), $this->getCollectionName(), ['y' => 2], ['$set' => ['x' => 2]], $options);

tests/Operation/FindTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,24 +166,25 @@ public function testExplainableCommandDocument(): void
166166
'batchSize' => 123,
167167
'collation' => ['locale' => 'fr'],
168168
'comment' => 'explain me',
169-
'cursorType' => Find::NON_TAILABLE,
170169
'hint' => '_id_',
171170
'limit' => 15,
172171
'max' => ['x' => 100],
173-
'maxAwaitTimeMS' => 500,
174172
'maxTimeMS' => 100,
175173
'min' => ['x' => 10],
176-
'modifiers' => ['foo' => 'bar'],
177174
'noCursorTimeout' => true,
178175
'oplogReplay' => true,
179176
'projection' => ['_id' => 0],
180177
'readConcern' => new ReadConcern(ReadConcern::LOCAL),
181-
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
182178
'returnKey' => true,
183179
'showRecordId' => true,
184180
'skip' => 5,
185181
'sort' => ['x' => 1],
186182
'let' => ['y' => 2],
183+
// Intentionally omitted options
184+
'cursorType' => Find::NON_TAILABLE,
185+
'maxAwaitTimeMS' => 500,
186+
'modifiers' => ['foo' => 'bar'],
187+
'readPreference' => new ReadPreference(ReadPreference::SECONDARY_PREFERRED),
187188
'typeMap' => ['root' => 'array'],
188189
];
189190
$operation = new Find($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1], $options);

0 commit comments

Comments
 (0)