Rename a collection in MongoDB
Renaming a collection in MongoDB is quite simple. When you rename a collection, it obtains a lock on the collection till the rename process is complete.
Advertisements
Syntax
db.collection.renameCollection("new_name_for_collection")
Example
> db.poopcode_users.renameCollection("users") { "ok" : 1 }
Here the collection ‘poopcode_users‘ is renamed to ‘users‘.