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

Invalid Hash Keys are silently ignored

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 12_01_17
    • Component/s: None
    • Labels:
      None

      Description

      MongoDB does not allow dots in hash keys.

      If the user is ignorant about this and tries to persist a Hash with a key containing a dot, there will be no warning or error.
      Mongoid 2.0.1 just ignores the key - and leaves the user puzzled about what's going on.

      IMHO it would be cleaner and more transparent if you'd set an error, similar to a failed validation, saying "Hash key can not contain dots" , and to refuse saving the Hash

      e.g.
      class Foo
      include Mongoid::Document
      field :ips, :type => Hash
      end

      f = Foo.new
      f.ips[ '192.168.1.1' ] = 1
      f.save
      => true
      f.errors
      => {}

      Foo.last.ips
      => nil

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            tilo Tilo S
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: