Reloading documents

Skip to first unread message

Nolan Darilek

Jun 29, 2009, 11:31:25 AM6/29/09
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


Matt Aimonetti

Jun 29, 2009, 6:17:17 PM6/29/09
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

Nov 2, 2011, 4:55:39 PM11/2/11
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.



Samuel Lown

Nov 3, 2011, 7:03:10 AM11/3/11

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:

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.



You received this message because you are subscribed to the Google Groups "CouchRest" group.
To view this discussion on the web visit
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply all
Reply to author
0 new messages