Search code examples
ruby-on-railsembedded-resourcedocumentsmongoid

update embedded documents mongodb with mongoid


I am having problem updating the embedded documents in mongodb.
I have a following scenario. A User model has address as the embedded docs.
I am able to embed the address to the parent model ie; User model but i still cant figure out how to update the address embedded even though i have the _id of the address embedded

Please help
Thanks


Solution

  • You have to retrieve the embedded document from the parent and then make the update operation, e.g:

    address = user.address
    address.update_attributes(:street => "foo")