spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Enhance MongoRepository.save() to ignore/not-unset unknown properties on save() [DATAMONGO-754] #1686

Open spring-projects-issues opened 11 years ago

spring-projects-issues commented 11 years ago

James Cole opened DATAMONGO-754 and commented

We're using MongoRepository as much as possible to keep the number of custom queries throughout our code to a minimum (only using them in performance critical places).
I've recently been trying to share @Document entities between projects (DRY and all that), but noticed that if one project uses findOne() and then save() on an entity that was updated by the other project which had a new property, the save() wipes out any attributes for which it doesn't already have explicitly defined matching properties in the pojo entity.

It'd be great if the framework could keep track of unknown attributes on an entity and then either ignore (maybe not easily possible with mongo) or at least re-persist the original values on save() instead of just wiping them.

The c-sharp mongo driver seems to have a good way to handle this by allowing you to put a placeholder [BsonExtraElements] annotation on a generic BsonDocument property to support non-obliteration of unknown properties: http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/#supporting-extra-elements It'd be great to see that in the spring data framework as well


2 votes, 3 watchers

poran-chowdury commented 1 year ago

Is there any solution or alternative way to handle it?

jh8nluiz commented 1 year ago

I'm having the same difficulty. I'm trying some alternative using repositories customization.

poran-chowdury commented 1 year ago

@jh8nluiz if you find any alternative solution please help me.