Ehud
unread,Apr 6, 2011, 6:37:45 AM4/6/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Mongoid
Hi all,
I'm trying to use a hash field to store data in a document as follows:
class User
include Mongoid::Document
field :game_stats, :type=>Hash
end
It seems like updates to hash member attributes are not saved to the
database though. Here's the console commands and output I'm getting:
# initialize the user object and create the hash
>> u=User.first
>>u.game_stats["143"] = {"playcount"=>0}
=> {"playcount"=>0}
>> u.game_stats["143"]["playcount"]
=> 0
>> u.save!
=> true
# reload the object and increment playcount
>> u.reload
>> u.game_stats["143"]["playcount"]
=> 0
>> u.game_stats["143"]["playcount"] += 1
=> 1
>> u.save!
# reload the object, playcount was not saved
>> u.reload
>> u.game_stats["143"]["playcount"]
=> 0
There were actually a few times where it did persist, but I couldn't
figure out the pattern.
Am I doing something wrong here? Using the native mongo client works
fine.