@@ -52,27 +52,7 @@ public static function createWithCollection(Collection $collection, array $optio
52
52
);
53
53
}
54
54
55
- public function withCollection (Collection $ collection ): self
56
- {
57
- /* Prohibit mixing Collections associated with different Manager
58
- * objects. This is not technically necessary, since the Collection is
59
- * only used to derive a namespace and encoding options; however, it
60
- * may prevent a user from inadvertently mixing writes destined for
61
- * different deployments. */
62
- if ($ this ->manager !== $ collection ->getManager ()) {
63
- throw new InvalidArgumentException ('$collection is associated with a different MongoDB\Driver\Manager ' );
64
- }
65
-
66
- return new self (
67
- $ this ->bulkWriteCommand ,
68
- $ this ->manager ,
69
- $ collection ->getNamespace (),
70
- $ collection ->getBuilderEncoder (),
71
- $ collection ->getCodec (),
72
- );
73
- }
74
-
75
- public function deleteOne (array |object $ filter , ?array $ options = null ): self
55
+ public function deleteMany (array |object $ filter , ?array $ options = null ): self
76
56
{
77
57
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
78
58
@@ -84,12 +64,12 @@ public function deleteOne(array|object $filter, ?array $options = null): self
84
64
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
85
65
}
86
66
87
- $ this ->bulkWriteCommand ->deleteOne ($ this ->namespace , $ filter , $ options );
67
+ $ this ->bulkWriteCommand ->deleteMany ($ this ->namespace , $ filter , $ options );
88
68
89
69
return $ this ;
90
70
}
91
71
92
- public function deleteMany (array |object $ filter , ?array $ options = null ): self
72
+ public function deleteOne (array |object $ filter , ?array $ options = null ): self
93
73
{
94
74
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
95
75
@@ -101,7 +81,7 @@ public function deleteMany(array|object $filter, ?array $options = null): self
101
81
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
102
82
}
103
83
104
- $ this ->bulkWriteCommand ->deleteMany ($ this ->namespace , $ filter , $ options );
84
+ $ this ->bulkWriteCommand ->deleteOne ($ this ->namespace , $ filter , $ options );
105
85
106
86
return $ this ;
107
87
}
@@ -160,7 +140,7 @@ public function replaceOne(array|object $filter, array|object $replacement, ?arr
160
140
return $ this ;
161
141
}
162
142
163
- public function updateOne (array |object $ filter , array |object $ update , ?array $ options = null ): self
143
+ public function updateMany (array |object $ filter , array |object $ update , ?array $ options = null ): self
164
144
{
165
145
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
166
146
$ update = $ this ->builderEncoder ->encodeIfSupported ($ update );
@@ -181,20 +161,16 @@ public function updateOne(array|object $filter, array|object $update, ?array $op
181
161
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
182
162
}
183
163
184
- if (isset ($ options ['sort ' ]) && ! is_document ($ options ['sort ' ])) {
185
- throw InvalidArgumentException::expectedDocumentType ('"sort" option ' , $ options ['sort ' ]);
186
- }
187
-
188
164
if (isset ($ options ['upsert ' ]) && ! is_bool ($ options ['upsert ' ])) {
189
165
throw InvalidArgumentException::invalidType ('"upsert" option ' , $ options ['upsert ' ], 'boolean ' );
190
166
}
191
167
192
- $ this ->bulkWriteCommand ->updateOne ($ this ->namespace , $ filter , $ update , $ options );
168
+ $ this ->bulkWriteCommand ->updateMany ($ this ->namespace , $ filter , $ update , $ options );
193
169
194
170
return $ this ;
195
171
}
196
172
197
- public function updateMany (array |object $ filter , array |object $ update , ?array $ options = null ): self
173
+ public function updateOne (array |object $ filter , array |object $ update , ?array $ options = null ): self
198
174
{
199
175
$ filter = $ this ->builderEncoder ->encodeIfSupported ($ filter );
200
176
$ update = $ this ->builderEncoder ->encodeIfSupported ($ update );
@@ -215,12 +191,36 @@ public function updateMany(array|object $filter, array|object $update, ?array $o
215
191
throw InvalidArgumentException::expectedDocumentOrStringType ('"hint" option ' , $ options ['hint ' ]);
216
192
}
217
193
194
+ if (isset ($ options ['sort ' ]) && ! is_document ($ options ['sort ' ])) {
195
+ throw InvalidArgumentException::expectedDocumentType ('"sort" option ' , $ options ['sort ' ]);
196
+ }
197
+
218
198
if (isset ($ options ['upsert ' ]) && ! is_bool ($ options ['upsert ' ])) {
219
199
throw InvalidArgumentException::invalidType ('"upsert" option ' , $ options ['upsert ' ], 'boolean ' );
220
200
}
221
201
222
- $ this ->bulkWriteCommand ->updateMany ($ this ->namespace , $ filter , $ update , $ options );
202
+ $ this ->bulkWriteCommand ->updateOne ($ this ->namespace , $ filter , $ update , $ options );
223
203
224
204
return $ this ;
225
205
}
206
+
207
+ public function withCollection (Collection $ collection ): self
208
+ {
209
+ /* Prohibit mixing Collections associated with different Manager
210
+ * objects. This is not technically necessary, since the Collection is
211
+ * only used to derive a namespace and encoding options; however, it
212
+ * may prevent a user from inadvertently mixing writes destined for
213
+ * different deployments. */
214
+ if ($ this ->manager !== $ collection ->getManager ()) {
215
+ throw new InvalidArgumentException ('$collection is associated with a different MongoDB\Driver\Manager ' );
216
+ }
217
+
218
+ return new self (
219
+ $ this ->bulkWriteCommand ,
220
+ $ this ->manager ,
221
+ $ collection ->getNamespace (),
222
+ $ collection ->getBuilderEncoder (),
223
+ $ collection ->getCodec (),
224
+ );
225
+ }
226
226
}
0 commit comments