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

Mongoid 3.1.6 $inc on hash field failing

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I have a Mongoid model with a hash field that looks like this:

      class DimensionStat
       include ::Mongoid::Document
       include ::Mongoid::Timestamps
      
       field :data, type: Hash
      
       attr_accessible :data
      end
      

      I pretend on runtime fill data with something like

      data: {
          'a' => 1,
          'b' => 2,
          ...
      }
      

      I need to perform increments on multiple keys atomically such as:

      'a' => -1,
      'b' => 5
      

      Somewhere I found that:

      instance.collection.find(_id: my_id).update("$inc" => {'data.a' => -1,
      'data.b' => 5})
      

      will do the trick but it doesn't, what am I doing wrong? I always get an empty hash!!!

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

              Created:
              Updated:
              Resolved: