Skip to content

How to exclude nested empty objects when saving? #2402

Answered by evanchooly
VladimirGK asked this question in Q&A
Discussion options

You must be logged in to vote

I'm guessing that sample doc at the bottom was meant to be address? At any rate, Morphia can't distinguish such a case. How Morphia, by way of how the driver works, persists an entity is that it writes each key/value pair in to BsonWriter. This is designed, at the driver level, to be an efficient "straight to the wire" mechanism (to simplify a little). It's designed to eliminate double writes (once to memory, then to the network) as much as possible. In order to do what you want, we'd have to serialize out that property, check the doc for emptiness, and then write it out. Fundamentally, that's much less efficient and is part of why Morphia moved away from that in 2.0.

If you would like to…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by VladimirGK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants