-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:
I'm trying to use inc on an embedded document, and it seems like the generated mongo command does not actually perform anything and the increment is lost.
To recreate the issue:
class User
include Mongoid::Document
embeds_many :game_stats
end
class GameStat
include Mongoid::Document
embedded_in :user
field :playcount, :type=>Integer, :default=>0
end
>> u=User.first
>> u.game_stats.create
>> u.save
>> u.game_stats.first.inc(:playcount, 1)
=> 1
Checking playcount again shows it did not in fact increment.
the mongo console shows the following command was sent:
mydbname.game_stats query:
update: { $inc:
{ playcount: 1 }} 1ms
Seems like it should be using $inc:
{game_stats.0.playcount : 1}, as it does with a regular save() call:
>> u.game_stats.first.playcount += 1
>> u.save
which translates into:
update mydbname.users query:
update: { $set:
}