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')
Written by Daniel Schmidt
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mongodb
Authors
dominikgarber
81.15K
sativaware
80.22K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#