Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data MongoDB "_class" bad design pattern

I have problems with Spring Data MongoDB project. My problem is _class property in all collection records. My user collection size is nearly 1.3 million records. All records have a _class property. This is problem and bad design for project. Because MongoDB is a document-based system. Size is a problem each record in the collections. User collection:

{ "_class" : "com.myproject.xxx.yy.aaa.bb.User", … }

What if I want to move the User class to another package? Why does Spring Data add a _class property to all records?

like image 430
ujava Avatar asked Aug 18 '12 10:08

ujava


1 Answers

I don't know what leads you to the assumption to improve the chances of getting advice if you're bashing the project your seeking advice for. Beyond that, when using a software library you might wanna assume that implementation details have been thought through and are the way they are for a reason.

If you had taken the time to consider read up the reference documentation you would have discovered the section explaining why the _class attribute is there in general as well as how to tweak the values written, how to customize the key or even turn off the type information written at all.

After reading up that stuff you can now go back to write perfectly fine software again in turn. Thanks!

PS: I've taken a bit of time to polish up your badly designed way of asking a question. ;)

like image 149
Oliver Drotbohm Avatar answered Oct 20 '22 03:10

Oliver Drotbohm