Avoid insert/upsert in mongodb when key is null

Viewed 21

I want to avoid inserting/modifying the key of a document when its value is null or empty. I am using mongodb version 5 and spring boot data version 2.4.

Example: If I have a model Person with name and surname as attributes, I want to avoid inserting surname key if its value is null or empty string.

Someone suggest me seeing to modify the WritingConverter bean in order to customize the process when POJO is converted to document but I do not know so much.

Any help?

0 Answers
Related