-
Type: Task
-
Resolution: Done
-
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!!!