@@ -67,27 +67,7 @@ public static function createWithCollection(Collection $collection, array $optio
6767 );
6868 }
6969
70- public function withCollection (Collection $ collection ): self
71- {
72- /* Prohibit mixing Collections associated with different Manager
73- * objects. This is not technically necessary, since the Collection is
74- * only used to derive a namespace and encoding options; however, it
75- * may prevent a user from inadvertently mixing writes destined for
76- * different deployments. */
77- if ($ this ->manager !== $ collection ->getManager ()) {
78- throw new InvalidArgumentException ('$collection is associated with a different MongoDB\Driver\Manager ' );
79- }
80-
81- return new self (
82- $ this ->bulkWriteCommand ,
83- $ this ->manager ,
84- $ collection ->getNamespace (),
85- $ collection ->getBuilderEncoder (),
86- $ collection ->getCodec (),
87- );
88- }
89-
90- public function deleteOne (array |object $ filter , ?array $ options = null ): self
70+ public function deleteMany (array |object $ filter , ?array $ options = null ): self
9171 {
9272 $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
9373
@@ -99,12 +79,12 @@ public function deleteOne(array|object $filter, ?array $options = null): self
9979 throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
10080 }
10181
102- $ this ->bulkWriteCommand ->deleteOne ($ this ->namespace , $ filter , $ options );
82+ $ this ->bulkWriteCommand ->deleteMany ($ this ->namespace , $ filter , $ options );
10383
10484 return $ this ;
10585 }
10686
107- public function deleteMany (array |object $ filter , ?array $ options = null ): self
87+ public function deleteOne (array |object $ filter , ?array $ options = null ): self
10888 {
10989 $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
11090
@@ -116,7 +96,7 @@ public function deleteMany(array|object $filter, ?array $options = null): self
11696 throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
11797 }
11898
119- $ this ->bulkWriteCommand ->deleteMany ($ this ->namespace , $ filter , $ options );
99+ $ this ->bulkWriteCommand ->deleteOne ($ this ->namespace , $ filter , $ options );
120100
121101 return $ this ;
122102 }
@@ -175,7 +155,7 @@ public function replaceOne(array|object $filter, array|object $replacement, ?arr
175155 return $ this ;
176156 }
177157
178- public function updateOne (array |object $ filter , array |object $ update , ?array $ options = null ): self
158+ public function updateMany (array |object $ filter , array |object $ update , ?array $ options = null ): self
179159 {
180160 $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
181161 $ update = $ this ->builderEncoder ->encodeIfSupported ($ update );
@@ -196,20 +176,16 @@ public function updateOne(array|object $filter, array|object $update, ?array $op
196176 throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
197177 }
198178
199- if (isset ($ options ['sort ' ]) && ! is_document ($ options ['sort ' ])) {
200- throw InvalidArgumentException::expectedDocumentType ('"sort" option ' , $ options ['sort ' ]);
201- }
202-
203179 if (isset ($ options ['upsert ' ]) && ! is_bool ($ options ['upsert ' ])) {
204180 throw InvalidArgumentException::invalidType ('"upsert" option ' , $ options ['upsert ' ], 'boolean ' );
205181 }
206182
207- $ this ->bulkWriteCommand ->updateOne ($ this ->namespace , $ filter , $ update , $ options );
183+ $ this ->bulkWriteCommand ->updateMany ($ this ->namespace , $ filter , $ update , $ options );
208184
209185 return $ this ;
210186 }
211187
212- public function updateMany (array |object $ filter , array |object $ update , ?array $ options = null ): self
188+ public function updateOne (array |object $ filter , array |object $ update , ?array $ options = null ): self
213189 {
214190 $ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
215191 $ update = $ this ->builderEncoder ->encodeIfSupported ($ update );
@@ -230,12 +206,36 @@ public function updateMany(array|object $filter, array|object $update, ?array $o
230206 throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
231207 }
232208
209+ if (isset ($ options ['sort ' ]) && ! is_document ($ options ['sort ' ])) {
210+ throw InvalidArgumentException::expectedDocumentType ('"sort" option ' , $ options ['sort ' ]);
211+ }
212+
233213 if (isset ($ options ['upsert ' ]) && ! is_bool ($ options ['upsert ' ])) {
234214 throw InvalidArgumentException::invalidType ('"upsert" option ' , $ options ['upsert ' ], 'boolean ' );
235215 }
236216
237- $ this ->bulkWriteCommand ->updateMany ($ this ->namespace , $ filter , $ update , $ options );
217+ $ this ->bulkWriteCommand ->updateOne ($ this ->namespace , $ filter , $ update , $ options );
238218
239219 return $ this ;
240220 }
221+
222+ public function withCollection (Collection $ collection ): self
223+ {
224+ /* Prohibit mixing Collections associated with different Manager
225+ * objects. This is not technically necessary, since the Collection is
226+ * only used to derive a namespace and encoding options; however, it
227+ * may prevent a user from inadvertently mixing writes destined for
228+ * different deployments. */
229+ if ($ this ->manager !== $ collection ->getManager ()) {
230+ throw new InvalidArgumentException ('$collection is associated with a different MongoDB\Driver\Manager ' );
231+ }
232+
233+ return new self (
234+ $ this ->bulkWriteCommand ,
235+ $ this ->manager ,
236+ $ collection ->getNamespace (),
237+ $ collection ->getBuilderEncoder (),
238+ $ collection ->getCodec (),
239+ );
240+ }
241241}
0 commit comments