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();
|
}
|
}
|
Attachments
Issue Links
- related to
-
JAVA-2780 Ensure MongoDatabase/MongoCollection unit tests, test optional options.
-
- Backlog
-