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

Mongoid 7.5 changes creation behavior with dotted keys

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      When upgrading from Mongoid 7.4.0 to Mongoid 7.5.1 we're detecting a behavioral change that doesn't seem to be documented in the release notes.

      It might not be intended as the expected behavior is still documented for version 8.0.

      We're defining a document as follows:

      class Something
        include Mongoid::Document
      
        store_in collection: 'some_things'
      
        field :n, type: String
        field :h, type: Hash, default: {}
      
        validates :n, presence: true
      
        def self.model_name
          ActiveModel::Name.new(self, nil, 'foo')
        end
      end
      

      Behavior with Mongoid 7.4:

      Something.create(n: 'test', h: { 'some.key': 'value' })
      #! BSON::String::IllegalKey: 'some.key' is an illegal key in MongoDB. Keys may not start with '$' or contain a '.'.
      #! from /Users/simonc/.gem/ruby/2.7.6/gems/bson-4.15.0/lib/bson/hash.rb:43:in `put_hash'
      

      Behavior with Mongoid 7.5:

      Something.create(n: 'test', h: { 'some.key': 'value' })
      #=> #<Something _id: 62e10ef0c24c842695b6517e, n: "test", h: {:"some.key"=>"value"}>
      

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            simon@textmaster.com Simon Courtois
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: