[ACCEPTED]-Spring Data MongoDB "_class" bad design pattern-spring-data

Accepted answer
Score: 25

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

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

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

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

Score: 3

For people visiting this more recently, look 18 at the @TypeAlias annotation that allows 17 you to declare the value that will be put 16 in _class, and therefore a smaller value 15 can be used.

This should partially answer 14 @Eric2201's question above too, where he 13 asks about a different type attribute. I'm 12 not sure that having a different and therefore 11 inconsistent attribute would be a good idea, I 10 am happy with _class. You can of course 9 add any field that you want to the document 8 though.

Nobody asked about it here, but just 7 FYI to complete this you can mix types in 6 the same collection. If you want to restrict 5 a document search based on type it doesn't 4 happen automatically in Spring Mongo even 3 though MongoTemplate asks for the type in 2 the "find" methods; you have add 1 _class to the query yourself.

More Related questions