Reloading documents

24 views
Skip to first unread message

Nolan Darilek

unread,
Jun 29, 2009, 11:31:25 AM6/29/09
to couc...@googlegroups.com
Is there any way to reload a document's properties, similar to DM/AR's
reload method? I have two scheduled tasks that update the same document
but different properties, so each update shouldn't create an application
state conflict, but if they run at the same time then they're saving
documents with different _revs. So I'd like to wrap the save in a block
that catches 409's, sleeps for a small random interval, reloads the doc
and tries again until the save succeeds.

Right now I'm fetching a new copy into a local variable and doing the
update to that, but it'd be neater if I could just run "reload" and edit
self.

Thanks.

Matt Aimonetti

unread,
Jun 29, 2009, 6:17:17 PM6/29/09
to couc...@googlegroups.com
There isn't any reload mechanism currently available, what would be good would be to fetch the document using the id and if the rev didn't change, then don't touch the object otherwise update it. (this way you can syn your local changes with the remote version)

The other option is to catch a 409 and merge the docs yourself. I did that on a small app I wrote, it turned out very clean.

- Matt

Mark Ellul

unread,
Nov 2, 2011, 4:55:39 PM11/2/11
to couc...@googlegroups.com
Hi Matt,

I know this is a super old thread, but I was wondering when you mention merging the documents, did you use any generic trick or approach to do this? or did you literally copy attribute for attribute?

I am getting a couple of sporadic 409 errors so I would like a mechanism to handle it better.

Regards

Mark

Samuel Lown

unread,
Nov 3, 2011, 7:03:10 AM11/3/11
to couc...@googlegroups.com
Hi,

In CouchRest Model you can call #reload and that should work fine. If your using CouchRest raw, then I'd guess you could do a merge of the Document's attributes hash. (In the latest CouchRest, hash related calls on the are forwarded to the _attributes hash: https://github.com/couchrest/couchrest/blob/master/lib/couchrest/attributes.rb)

Of course, the base of the problem if you're getting 409 conflict errors, is because the document is being update elsewhere, after you've read it. While a relational database will allow you to overwrite specific values and leave the object in a potentially unstable state, CouchDB won't. It might be a good idea to re-evaluate why this is happening and try to avoid it.

Cheers,

sam 

--
You received this message because you are subscribed to the Google Groups "CouchRest" group.
To view this discussion on the web visit https://groups.google.com/d/msg/couchrest/-/vJxgZ8YhzaYJ.
To post to this group, send email to couc...@googlegroups.com.
To unsubscribe from this group, send email to couchrest+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/couchrest?hl=en.



--
www.samlown.com
www.autofiscal.com
www.planetaki.com/sam
Reply all
Reply to author
Forward
0 new messages