I need to convert an embedded document into my own collection, so it can be referenced from another collection.
Suppose I have a Parent that inserts a lot of Childs . I thought about it:
Parent.all.each do |p| p.childs.all.each do |c| c.raw_attributes['parent_id'] = p.id end p.save!
Is this an option? Ideally, I would run this in the console, and I would only change the mongoid mappings from embed_* to has_* , so I didn't need to change the rest of my code or use another collection as a stage.
Miguel ping
source share