Skip to content

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

Open
@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions