开发者

Update mongodb document without updating embedded document and vice versa

开发者 https://www.devze.com 2023-01-06 18:57 出处:网络
I have a document with an embedded document in it. I have 2 forms, 1 that updates fields in document and one that updates fields in emdedded docs.

I have a document with an embedded document in it.

I have 2 forms, 1 that updates fields in document and one that updates fields in emdedded docs.

They are split into 2 forms as lots of fields in each etc and actually this is just a simple example of the structure of my app.

Everywhere else that i reference this data it makes most sense to store in one doc and not split them.

Problem is when i save say for 1 using update_attributes just开发者_JAVA技巧 the fields from form 1 get saved, then when i goto form 2 just the fields from for 2 are saved and i lose data saved in form 1.

Is there a way to skip saving an emdedded docuemnt with a callback, so i can say for example if come from form 1 ? dont update embedded doc. And if come from form 2 just save embedded doc ?

Hope this makes sense.

Any one help or advice ? Thanks Rick


Not sure how it's exposed in MongoMapper, but the MongoDB operation you're looking for is an update with $set to just set the fields you need. So if you drop down to the ruby driver it should be pretty easy to set just the fields you care about.

0

精彩评论

暂无评论...
验证码 换一张
取 消