How can I rename a collection in MongoDB?

Zugwalt picture Zugwalt · Jan 4, 2012 · Viewed 32k times · Source

Is there a dead easy way to rename a collection in mongo? Something like:

db.originalCollectionName.rename('newCollectionName');

And if not, what is the best way to go about effectively renaming one?

Answer

nav picture nav · Jan 4, 2012

Close. Use db.originalCollectionName.renameCollection('newCollectionName')

See http://www.mongodb.org/display/DOCS/renameCollection+Command