[JAVA-106] rename isn't working Created: 15/Apr/10  Updated: 29/Oct/10  Resolved: 18/May/10

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 2.0
Fix Version/s: 2.0

Type: Bug Priority: Minor - P4
Reporter: Mark Waschkowski Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, java 1.4 driver, mongo 1.3.3



 Description   

if I do:

db.requestStart();
db.setWriteConcern(WriteConcern.STRICT);
String colName = "testCollection";
DBCollection collection = db.getCollection(colName);
//mongodb.save(getTestObject(), colName);
//long size = collection.getCount();
//assert size == 1;
String colNewName = "testCollection2";
collection.rename(colNewName);
System.out.println("collection name = " + collection.getName());
assert collection.getName().equals(colNewName);
db.requestDone();

then I get:

com.mongodb.MongoException: rename failed:

{ "errmsg" : "assertion: source namespace does not exist" , "ok" : 0.0}

at com.mongodb.DBCollection.rename(DBCollection.java:499)
at com.refineddata.MongoDatabaseTest.testCreateExistsRenameDeleteCollection(MongoDatabaseTest.java:70)

which doesn't seem appropriate as namespace should exist, the collection itself exists.

If I save something in the code:

db.requestStart();
db.setWriteConcern(WriteConcern.STRICT);
String colName = "testCollection";
DBCollection collection = db.getCollection(colName);
mongodb.save(getTestObject(), colName);
long size = collection.getCount();
assert size == 1;
String colNewName = "testCollection2";
collection.rename(colNewName);
System.out.println("collection name = " + collection.getName());
assert collection.getName().equals(colNewName);
db.requestDone();

the following is printed:

collection name = testCollection

the following assertion fails (which shouldn't happen as no exception is thrown)
assert collection.getName().equals(colNewName);



 Comments   
Comment by Mark Waschkowski [ 18/May/10 ]

OK, thanks.

Comment by Eliot Horowitz (Inactive) [ 18/May/10 ]

rename() works at the db level, not the java level

so in the first case, as far as the db is concerned, the collection doesn't exist

in the 2nd case, the DBCollection object will never get changes.
you have to get the new one

I changed rename so it returns the new DBCollection

so you can do

collection = collection.rename( "newname" )

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