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

Yesterday while I was doing some test for the 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 a 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 the 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 of those collections or you may want precious data in that collection. You can use runCommand to rename those collections or to drop them.
db.runCommand({drop:"test.Profiling_28-08-2013"});
db.runCommand({drop:"test.post-old"});
Rename commands you may have to run against the admin database. For rename, you may have to use the 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: "test.post-old", to: "test.newCol"});

Tags

  • mongo
  • MongoDB Shell
  • Mongo Shell
  • mongodb administration
  • mongodb errors