[JAVA-2779] Rename collection with dropTarget stopped working Created: 09/Feb/18  Updated: 28/Oct/23  Resolved: 09/Feb/18

Status: Closed
Project: Java Driver
Component/s: Async
Affects Version/s: 3.6.2
Fix Version/s: 3.6.3

Type: Bug Priority: Major - P3
Reporter: Rintcius Blok Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-2780 Ensure MongoDatabase/MongoCollection ... Backlog

 Description   

In mongodb-driver-async version 3.6.2 the code below does not rename the collection anymore. Instead it gives the following exception:

com.mongodb.MongoCommandException: Command failed with error 48: 'target namespace exists' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "target namespace exists", "code" : 48, "codeName" : "NamespaceExists" }

Using version 3.5.0, the same code does rename the collection, as expected.

import java.util.concurrent.CountDownLatch;
 
import com.mongodb.async.*;
import com.mongodb.async.client.*;
import com.mongodb.client.model.*;
import org.bson.Document;
 
public class RenameTest {
 
  public static void main(final String[] args) throws InterruptedException {
 
      MongoClient client = MongoClients.create();
 
      MongoDatabase db = client.getDatabase("renametest");
 
      MongoCollection<Document> src = db.getCollection("src");
      MongoCollection<Document> dst = db.getCollection("dst");
 
      Document doc = new Document("name", "rename");
 
      final CountDownLatch l1 = new CountDownLatch(1);
      src.insertOne(doc, new SingleResultCallback<Void>() {
          @Override
          public void onResult(final Void result, final Throwable t) {
              System.out.println("Inserted src");
              l1.countDown();
          }
      });
      l1.await();
 
      final CountDownLatch l2 = new CountDownLatch(1);
      dst.insertOne(doc, new SingleResultCallback<Void>() {
          @Override
          public void onResult(final Void result, final Throwable t) {
              System.out.println("Inserted dst");
              l2.countDown();
          }
      });
      l2.await();
 
      final CountDownLatch l3 = new CountDownLatch(1);
      src.renameCollection(dst.getNamespace(), new RenameCollectionOptions().dropTarget(true), new SingleResultCallback<Void>() {
          @Override
          public void onResult(final Void result, final Throwable t) {
              System.out.println("Rename result");
              System.out.println(result);
              System.out.println(t);
              l3.countDown();
          }
      });
      l3.await();
  }
}



 Comments   
Comment by Rintcius Blok [ 12/Feb/18 ]

Thanks for the quick fix! When is the release of 3.6.3 expected?

Comment by Githook User [ 09/Feb/18 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Async: Ensure renameCollection options are passed to the operation.

JAVA-2779
Branch: 3.6.x
https://github.com/mongodb/mongo-java-driver/commit/4d90becbe5725a0b42dfbbea8c2c9e9dd1eb359e

Comment by Githook User [ 09/Feb/18 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Async: Ensure renameCollection options are passed to the operation.

JAVA-2779
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/ddb7a7e17e20c7662e1eec79d0c66fec0170ea3d

Comment by Rintcius Blok [ 09/Feb/18 ]

Hi Ross, thanks for your quick response. MongoDB version I am running is `3.4.4`.

Comment by Ross Lawley [ 09/Feb/18 ]

Hi rintcius,

Thanks for the ticket and test case, what version of MongoDB are you running?

I'll investigate and report any findings back.

Ross

Generated at Thu Feb 08 08:58:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.