0
我不明白Mongoid的原子方法推動。Mongoid帶原子的持久性推動
我有這個文件:
class Campaign
include Mongoid::Document
field :messages, :type => Array # Array of hashes
end
現在在控制檯,但消息一齣戲它不堅持。舉個例子:
>> campaign = Campaign.last
=> #<Campaign _id: 4dc2b6617e296d53f000000d,...
>> data = {:from => '[email protected]'}
=> {:from=>"[email protected]"}
>> campaign.push(:messages, data)
=> [{:from=>"[email protected]"}]
日誌現在說:
MONGODB blabla_development['campaigns'].update({"_id"=>BSON::ObjectId('4dc2b6617e296d53f000000d')}, {"$push"=>{:messages=>{:from=>"[email protected]"}}})
但是,如果查詢這個文件再次,消息字段是零:
>> campaign = Campaign.last
=> #<Campaign _id: 4dc2b6617e296d53f000000d,...
>> campaign.messages
=> nil
我如何能堅持這個數據?
謝謝