Morphia does not store null/empty fields by default. Is there a way to enable this?
In the interests of answering the question asked, you can:
MapperOptions.setStoreNulls(boolean)
MapperOptions.setStoreEmpties(boolean)
.You can get a MapperOptions
reference from the mapper instance by Mapper.getOptions()
.
However, the Mapper
class is internal only and is deprecated:
this class will be internalized in 2.0
Same deprecation applies for before mentioned setter methods in class MapperOptions
, instead the JavaDocs recommend:
use the Builder instead
This is a feature and one of the points of a document store. Don't waste space (both on RAM, disk, and for transfers) on missing data.
If you use primitive types instead of object types, a value will be saved, since there's no null value. For example long
instead of Long
. For String
you'd need to store an empty (or some dummy) value.
Out of interest: Why would you want to explicitly store null / empty fields? Maybe there's a better solution for what you are trying to do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With