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

Hash field in a Mongoid document won't be updated if field name contains a dot or a dollar

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.14
    • Affects Version/s: None
    • Component/s: None
    • None

      Seen on Mongo 2.5.1.

      Say you have this object

      class Article
        include Mongoid::Document
      
        field :simple_field
        field :some_metadata, type: Hash
      end
      

      Then the

      Unable to find source-code formatter for language: update_attributes```. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
       will silently fail.
      
      

      ruby
      article = Article.new :simple_field => 'foo'
      article.save

      article.update_attributes :simple_field => 'bar', some_metadata =>

      { "datum.1" => "value" }

      h1. In memory, everything's fine
      puts article.simple_field # bar
      puts article.some_metadata # { "datum.1" => "value" }

      But when you read fields from the database

      puts article.reload.simple_field # foo
      puts article.reload.some_metadata # nil

      Shouldn't mongoid escape hash keys containing 

      .

       or 

      $` before storing them in mongoid?

            Assignee:
            Unassigned Unassigned
            Reporter:
            ssaunier ssaunier
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: