Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update existing documents with Spring Data MongoDB type information after type renames?

I am using mongodb with spring and I have some subdocuments that are derived from one base class, mongo uses the '_class' property to find out what is the correct type to convert to, but now I have changed the package name and the collection still has documents with old package name, how can I tell mongo what custom conversions to do ?

like image 782
jacob Avatar asked Sep 16 '25 08:09

jacob


1 Answers

first of all for next time to decouple your package/class name from _class variable, use: @TypeAlias("name") annotation on your pojo. then _class will have the value "name"

The easiest solution in my opinion is to update your pojo with TypeAlias and update your collection's _class field with it's new value

Read about Type mapping over here: http://docs.spring.io/spring-data/data-mongodb/docs/current/reference/html/#mongo-template.type-mapping

like image 133
royB Avatar answered Sep 19 '25 05:09

royB