-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Attributes
-
None
In MongoDB there is a distinction between "unset" and "null".
- "null" is a value, e.g. Customer.set(name: nil)
- "unset" is the absence of any value, e.g. the empty set Customer.unset(:name)
Null causes all sorts of problems especially with indexes, for example it is not ignored in sparse indexes; the key remains in the document.
Unfortunately in Ruby, the demongoization causes both the null and unset cases to be represented as "nil", so it is impossible from the value alone to determine the actual state of the DB.
It would be really nice if it were possible to have a config mode in Mongoid such that the value null (nil in Ruby) unsets the value from the DB itself, it would create much more consistent/intuitive behavior.
- is duplicated by
-
MONGOID-3653 Distinguish between nil and "unset" in DB (propose to introduce Mongoid::Undefined)
- Closed
- is related to
-
MONGOID-4592 Support the :local_default or :store_default option to fields, which defines a default value for document fields without persisting that value to the database
- Closed