I've asked about this before, and I've come up with a workaround for myself,
but it's not pretty
I have an app that listens to _changes from a CouchDB database in order to act
on changes to documents. This involves comparing the current document (which
_changes provides via include_docs=true) with the previous revision (the
document that the change acted on). The biggest problem I have is getting a
document that's just been deleted ("deleted":true in the change feed).
Using include_docs=true, the returned doc for a deletion is a deleted doc stub.
So, I want to get the immediately previous revision (ie: the doc that was just
deleted), in order to find out about the deleted document. But, I can't do a
revs=true or revs_info=true on the document in order to get previous revision
ids. CouchDB returns a 404 Object Not Found with
{"error":"not_found","reason":"deleted"}.
The only way I've figured out how to get what I need is to resurrect the
document by PUT-ting an empty document back to the database, getting the
revisions list with the resurrected doc in place, then deleting it again.
Provided I have the revisions ids, CouchDB seems happy to provide past
revisions of a document regardless of whether the document is currently deleted
or not.
Is there a better way to do this?
In general, the functionality I need is to be able to have _changes send not
only the latest revision of a document, but the immediately previous revision
(ie: the document that the change acted on), if possible. That way, my app can
figure out what's different and act appropriately. Getting the revisions list
for a document and GET-ting the previous revision is ok, except for deletions,
as explained above.
Thanks,
King Chung Huang
Technology Solutions Analyst
Information Technologies
University of Calgary