@@ -67,27 +67,7 @@ public static function createWithCollection(Collection $collection, array $optio
67
67
);
68
68
}
69
69
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
91
71
{
92
72
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
93
73
@@ -99,12 +79,12 @@ public function deleteOne(array|object $filter, ?array $options = null): self
99
79
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
100
80
}
101
81
102
- $ this ->bulkWriteCommand ->deleteOne ($ this ->namespace , $ filter , $ options );
82
+ $ this ->bulkWriteCommand ->deleteMany ($ this ->namespace , $ filter , $ options );
103
83
104
84
return $ this ;
105
85
}
106
86
107
- public function deleteMany (array |object $ filter , ?array $ options = null ): self
87
+ public function deleteOne (array |object $ filter , ?array $ options = null ): self
108
88
{
109
89
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
110
90
@@ -116,7 +96,7 @@ public function deleteMany(array|object $filter, ?array $options = null): self
116
96
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
117
97
}
118
98
119
- $ this ->bulkWriteCommand ->deleteMany ($ this ->namespace , $ filter , $ options );
99
+ $ this ->bulkWriteCommand ->deleteOne ($ this ->namespace , $ filter , $ options );
120
100
121
101
return $ this ;
122
102
}
@@ -175,7 +155,7 @@ public function replaceOne(array|object $filter, array|object $replacement, ?arr
175
155
return $ this ;
176
156
}
177
157
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
179
159
{
180
160
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
181
161
$ update = $ this ->builderEncoder ->encodeIfSupported ($ update );
@@ -196,20 +176,16 @@ public function updateOne(array|object $filter, array|object $update, ?array $op
196
176
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
197
177
}
198
178
199
- if (isset ($ options ['sort ' ]) && ! is_document ($ options ['sort ' ])) {
200
- throw InvalidArgumentException::expectedDocumentType ('"sort" option ' , $ options ['sort ' ]);
201
- }
202
-
203
179
if (isset ($ options ['upsert ' ]) && ! is_bool ($ options ['upsert ' ])) {
204
180
throw InvalidArgumentException::invalidType ('"upsert" option ' , $ options ['upsert ' ], 'boolean ' );
205
181
}
206
182
207
- $ this ->bulkWriteCommand ->updateOne ($ this ->namespace , $ filter , $ update , $ options );
183
+ $ this ->bulkWriteCommand ->updateMany ($ this ->namespace , $ filter , $ update , $ options );
208
184
209
185
return $ this ;
210
186
}
211
187
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
213
189
{
214
190
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
215
191
$ update = $ this ->builderEncoder ->encodeIfSupported ($ update );
@@ -230,12 +206,36 @@ public function updateMany(array|object $filter, array|object $update, ?array $o
230
206
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
231
207
}
232
208
209
+ if (isset ($ options ['sort ' ]) && ! is_document ($ options ['sort ' ])) {
210
+ throw InvalidArgumentException::expectedDocumentType ('"sort" option ' , $ options ['sort ' ]);
211
+ }
212
+
233
213
if (isset ($ options ['upsert ' ]) && ! is_bool ($ options ['upsert ' ])) {
234
214
throw InvalidArgumentException::invalidType ('"upsert" option ' , $ options ['upsert ' ], 'boolean ' );
235
215
}
236
216
237
- $ this ->bulkWriteCommand ->updateMany ($ this ->namespace , $ filter , $ update , $ options );
217
+ $ this ->bulkWriteCommand ->updateOne ($ this ->namespace , $ filter , $ update , $ options );
238
218
239
219
return $ this ;
240
220
}
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
+ }
241
241
}
0 commit comments