File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -352,13 +352,19 @@ public function testRenameToSameDatabase(): void
352
352
353
353
public function testRenameToDifferentDatabase (): void
354
354
{
355
+ $ toDatabaseName = $ this ->getDatabaseName () . '_renamed ' ;
356
+ $ toDatabase = new Database ($ this ->manager , $ toDatabaseName );
357
+
358
+ /* When renaming an unsharded collection, mongos requires the source
359
+ * and target database to both exist on the primary shard. In practice, this
360
+ * means we need to create the target database explicitly.
361
+ * See: https://docs.mongodb.com/manual/reference/command/renameCollection/#unsharded-collections
362
+ */
355
363
if ($ this ->isShardedCluster ()) {
356
- $ this -> markTestSkipped ( ' TODO: mongos requires the target database to exist ' );
364
+ $ toDatabase -> foo -> insertOne ([ ' _id ' => 1 ] );
357
365
}
358
366
359
- $ toDatabaseName = $ this ->getDatabaseName () . '_renamed ' ;
360
367
$ toCollectionName = $ this ->getCollectionName () . '.renamed ' ;
361
- $ toDatabase = new Database ($ this ->manager , $ toDatabaseName );
362
368
$ toCollection = new Collection ($ this ->manager , $ toDatabaseName , $ toCollectionName );
363
369
364
370
$ writeResult = $ this ->collection ->insertOne (['_id ' => 1 ]);
Original file line number Diff line number Diff line change @@ -239,13 +239,19 @@ public function testRenameCollectionToSameDatabase(): void
239
239
240
240
public function testRenameCollectionToDifferentDatabase (): void
241
241
{
242
+ $ toDatabaseName = $ this ->getDatabaseName () . '_renamed ' ;
243
+ $ toDatabase = new Database ($ this ->manager , $ toDatabaseName );
244
+
245
+ /* When renaming an unsharded collection, mongos requires the source
246
+ * and target database to both exist on the primary shard. In practice, this
247
+ * means we need to create the target database explicitly.
248
+ * See: https://docs.mongodb.com/manual/reference/command/renameCollection/#unsharded-collections
249
+ */
242
250
if ($ this ->isShardedCluster ()) {
243
- $ this -> markTestSkipped ( ' TODO: mongos requires the target database to exist ' );
251
+ $ toDatabase -> foo -> insertOne ([ ' _id ' => 1 ] );
244
252
}
245
253
246
- $ toDatabaseName = $ this ->getDatabaseName () . '_renamed ' ;
247
254
$ toCollectionName = $ this ->getCollectionName () . '.renamed ' ;
248
- $ toDatabase = new Database ($ this ->manager , $ toDatabaseName );
249
255
$ toCollection = new Collection ($ this ->manager , $ toDatabaseName , $ toCollectionName );
250
256
251
257
$ bulkWrite = new BulkWrite ();
You can’t perform that action at this time.
0 commit comments