Got unauthorized error when renaming mongodb collection -
i using mongohq sandbox plan. in command prompt,
db["oldcollectionname"].renamecollection("newcollectionname", true)
works fine without using admin database.
however, got "unauthorized" exception when in java:
oldcollection.rename(newcollectionname);
since using mongohq sandbox plan, don't have access admin database. there way rename collection without creating new collection, copying on documents, , dropping old collection?
in java , using jongo can following:
mongocollection col = new jongo(dbconfigurer.getdb()).getcollection("code"); col.getdbcollection().rename("code45", true);
i've tested , works.
now using 'runcommand' (same using db.command) in following example:
db db = ....getdb(); jongo jongo = new jongo(db); jongo.runcommand("{ renamecollection : 'old_name', to: 'new_name', droptarget: true}");
i obtain same error have.
i read documentation have connect first admin database process of command not allowed, did same "admin" db, , obtain following error stack:
{ "serverused" : "localhost/127.0.0.1:27017" , "errmsg" : "exception: invalid collection name: new_name" , "code" : 15967 , "ok" : 0.0}
strange have such different behaviors...
Comments
Post a Comment