mongodb - Moped::Errors::OperationFailure when creating an embedded object -
i'm using mongoid 3.1.4 altogether moped 1.5.1, mongodb 2.4.1, , ruby 1.9.3.
i have next models:
class practice include mongoid::document embeds_many :distresses end class distress include mongoid::document embedded_in :practice end when seems working:
practice = practice.create practice.distresses.create but when place safe: true in config file , same, get:
moped::errors::operationfailure: operation: #<moped::protocol::command @length=82 @request_id=22 @response_to=0 @op_code=2004 @flags=[] @full_collection_name="collection.$cmd" @skip=0 @limit=-1 @selector={:getlasterror=>1, :safe=>true} @fields=nil> and actually, got error when creating distress in way. throws exception:
practice = practice.create distress = practice.distresses.build distress.save when check practice.distresses.count can see distresses created in database, exception mentioned above.
ok, after days able fix problem.
in distress model had before_create callback trying update field on practice parent object. somehow makes moped create wrong request makes mongodb fail.
i changed before_create callback after_create , working now.
hope helps else.
Comments
Post a Comment