Search code examples
javamorphia

Java: Morphia how easy is it to update a Collection with new field values


I'm new to this,

Let's say I have Collection "UserData" and there are 1000 Documents in the UserData.

Now I need to add one more field called "position".

Can I do this, how?, or how does it work?

Looking on the wiki Morphia but cannot find anything


Solution

  • Essentially, yeah, you can. There are implications, but significantly less than using a traditional ORM.

    With Morphia, if your persisted object has an instance variable that isn't set, its not included in the record in mongo. So adding another instance variable is pretty straightforward for mongo to retroactively map older records - they just get null for that variable (in my experience).

    Now if your application now absolutely depends on Position you'll have to update those 1000 records, but in general in my experience you can add the instance variable and it'll just work, easy as that.