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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -