You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Alex Rudyk <al...@gmail.com> on 2009/01/15 17:36:46 UTC

Why I have to know _rev to DELETE document?

Does anybody know,

Why I can't delete current document revision without specifying rev in
DELETE request, similar to how I can GET current document rev using:
GET /somedatabase/some_doc_id HTTP/1.0

Also why client may want to delete revision that is not last/current
revision of the document?

thx

Re: Why I have to know _rev to DELETE document?

Posted by Jeremy Wall <jw...@google.com>.
You don't have to know the rev so you can delete a particular revision. The
rev is needed in delete for the same reason you need it in delete. It shows
CouchDB that you are deleting an unmodified document.

if the rev doesn't match then CouchDB will know the document was modified
after you last looked at it and can notify you. It helps to maintain
consistency in the database when more than one client is using it and is a
primary principles of CouchDB's design.

On Thu, Jan 15, 2009 at 10:36 AM, Alex Rudyk <al...@gmail.com> wrote:

> Does anybody know,
>
> Why I can't delete current document revision without specifying rev in
> DELETE request, similar to how I can GET current document rev using:
> GET /somedatabase/some_doc_id HTTP/1.0
>
> Also why client may want to delete revision that is not last/current
> revision of the document?
>
> thx
>

Re: Why I have to know _rev to DELETE document?

Posted by Alex Rudyk <al...@gmail.com>.
It's a code snippet from couch_httpd.erl

db_doc_req(#httpd{method='DELETE'}=Req, Db, DocId) ->
    case extract_header_rev(Req, couch_httpd:qs_value(Req, "rev")) of
    missing_rev ->
        couch_httpd:send_error(Req, 412, <<"missing_rev">>,
            <<"Document rev/etag must be specified to delete">>);
    RevToDelete ->
        {ok, NewRev} = couch_db:delete_doc(Db, DocId, [RevToDelete]),
        send_json(Req, 200, {[
            {ok, true},
            {id, DocId},
            {rev, NewRev}
            ]})
    end;

Looks like exception will be thrown if no revision specified.

So I think _rev is mandatory parameter for DELETE.

2009/1/15 Noah Slater <ns...@apache.org>:
> On Thu, Jan 15, 2009 at 08:36:46AM -0800, Alex Rudyk wrote:
>> Also why client may want to delete revision that is not last/current
>> revision of the document?
>
> Document revisions may not mean what you think they mean:
>
>  http://wiki.apache.org/couchdb/Document_revisions
>
> Hope this helps,
>
> --
> Noah Slater, http://tumbolia.org/nslater
>

Re: Why I have to know _rev to DELETE document?

Posted by Noah Slater <ns...@apache.org>.
On Thu, Jan 15, 2009 at 08:36:46AM -0800, Alex Rudyk wrote:
> Also why client may want to delete revision that is not last/current
> revision of the document?

Document revisions may not mean what you think they mean:

  http://wiki.apache.org/couchdb/Document_revisions

Hope this helps,

-- 
Noah Slater, http://tumbolia.org/nslater