-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I am almost done with the process of upgrading a large app from mongoid2 to mongoid3, and today I fell into an issue which almost got me crazy. I finally came to the conclusion that mongoid3 will not persist an already existing document if it does not have an id.
So I have a parent document which does have an id. I can fetch this document with mongoid. This document has many embedded docs, but those do not have an id... making any changes to those and then calling Model#save on it returns true, but nothing is persisted.
Unfortunately, assiging an ID to those documents and then trying to have them persist does not work either. I have to launch the mongo shell, set an id from there, and then everything works.
My current only solution is to make a mongo script which will loop into the documents and set an id from there, and fix the code generating id-less embedded. Is there a way to fix this from mongoid instead?
EDIT: I'd also like to mention that the way mongoid act with those docs without an id is by assigning a new one. So the same resource always have a different id when I fetch it.