Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using Mongoid as my DB wrapper. I had a model with no inheritance and thousands of documents in the collection. I then refactored it to inherit from a base class. Now I can't retrieve the original data. I don't see it when querying the class or the base class.

How should I be handling this change? I see that Mongoid does allow inheritance and will store all the documents in the parent collection, then add a "_type" field for type differentiation. Should I migrate the data to a temp collection, deploy the code change and then migrate the temp data to the new base collection and set the _type field?

Thanks

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Decided to just do a dump of production to my local db. Then copy the documents to the new base class collection and verify the _type is set. Then finally restore it to production.

share|improve this answer
    
How did you copy the documents to the new base class? –  cilphex Jul 16 '13 at 4:06
    
After you import the collection, check that it has a _type field. If not, you can set it with db.<collection>.update({ '_type': null }, { $set: { '_type': "<Ruby model class name>" } }, { multi: true }); Then finally copy them to the new base class collection with: db.<collection>.copyTo("<parent_collection>"); –  Malachor Jul 17 '13 at 14:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.