b36luw
Last Updated: February 25, 2016
·
1.252K
· dsci
32b6de7d5abfe436f9b7e86c50f73eae

Renaming a MongoDb collection

Recently I accidentally had a typo in my Mongoid Rails model where I specified a collection name to store the documents in.

After playing around with my app I discovered my mistake - and having existing associations by now - I wanted to fix this. So I removed the typo from the code and at the end I had to rename the collection within MongoDB.

Let's say the wrong collection name was wordifycsmexternal_links and the correct name wordifycmsexternal_links. I fired up my Mongo shell, select the database and renamed the collection:

db.wordify_csm_external_links.renameCollection('wordify_cms_external_links')
Say Thanks
Respond