After renaming I can't access MongoDB collection! :(

Yesterday while I was doing some test for performance team, I renamed a collection. Actually I renamed system.profile into "Profiling_28-08-2013". Then I couldn't access it. I couldn't delete that collection use db.Profiling_28-08-2013.drop(). After renaming MongoDB shell can't access that object. 
1. JavaScript execution failed: ReferenceError: <Part of collection name> is not defined
 2. JavaScript execution failed: SyntaxError: Unexpected token ILLEGAL
 3. <Part of collection name> is not a legal ECMA-262 octal constant (shell):1
 4. SyntaxError: missing ; before statement (shell):1
 5. ReferenceError: <Part of collection name> is not defined (shell):1
Those errors I got by trying combination against MongoDB several versions. First two errors I got from  MongoDB 2.4 and the rest from MongoDB 2.2.

If you have "-" inside your new collection name without any numbers you will get first error. Rest errors you will only get if you have "-08" like parts in your collection names.

MongoDB version 2.4.3 Shell version 2.4.3
MongoDB version 2.2.3 Shell version 2.2.3

Now you may want to get rid from those collections or you may want precious data in those collection. You can use runCommand to rename those collections or to drop them.
Rename commands you may have to run against the admin database. For rename you may have to use complete namespace. But dropping you can do with just collection name. It is recommended to use namespace when you are dropping.
db.runCommand({ renameCollection: "test.Profiling_28-08-2013", to: "test.newCol"});
db.runCommand({ renameCollection: "", to: "test.newCol"});


  1. And if you ever were to wear these separately, everybody would
    see your bra. Look for bold prints to become mainstream on single-breasted coats and other
    items of men's clothing. If you have eyeglasses that could do
    these items, it's surely no surprise they're liked by VIPs.

    Visit my site - lace bodycon dress tumblr


Post a Comment