Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-4611

Option to unset nil-valued fields in DB

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Attributes
    • Labels:
      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            johnnyshields Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: