spring-projects / spring-projects/spring-data-mongodb

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

Open
#1,686 3 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 30, 2020.

in: repository type: enhancement
Dominant language
Java
Stars
1.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.