You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Hank Knight <hk...@gmail.com> on 2013/12/30 21:10:31 UTC

CouchDB: Returning latest revision as update function result

I use this in my update function:
return [doc, doc._rev]

When a document is updated using the update function, I want the
latest revision information to be returned, however that returns
revision information of the document BEFORE being updated by the
update function.  So it actually always returns a previous revision
and not the latest revision.

Is it possible for the update function to return the latest revision
information or will I have to get this from a separate query after
updating the document with the update function?

Re: CouchDB: Returning latest revision as update function result

Posted by Robert Samuel Newson <rn...@apache.org>.
It's worth remembering that the update hasn't yet happened at the point
that the update handler returns (it could even fail with a conflict!).

The return value is two parts, the first is the document you want
couchdb to attempt to update and the second is the response to return to
the user.

B.


On 30/12/2013 20:59, Stanley Iriele wrote:
> No sadly there isn't and that is by design.
> 
> In the city text of an update handler you only have the doc before it gets
> persisted to disk so you don't know the new revision till afterwards
> On Dec 30, 2013 3:36 PM, "Hank Knight" <hk...@gmail.com> wrote:
> 
>> Thanks.  Accessing the headers is better than nothing but is there any
>> way to get the revision information returned like this?
>> return [doc, doc._rev]
>>
>> On Mon, Dec 30, 2013 at 4:17 PM, Stanley Iriele <si...@gmail.com>
>> wrote:
>>> Yes...the new ID and rev are returned as headers.
>>>
>>> X-Couch-Id is the  new ID
>>> X-Couch-Update-Newrev is the new revision
>>>
>>> Here's where its mentioned in the docs
>>>
>>>
>> http://docs.couchdb.org/en/latest/api/ddoc/render.html?highlight=update#put--db-_design-ddoc-_update-func-docid
>>> On Dec 30, 2013 3:11 PM, "Hank Knight" <hk...@gmail.com> wrote:
>>>
>>>> I use this in my update function:
>>>> return [doc, doc._rev]
>>>>
>>>> When a document is updated using the update function, I want the
>>>> latest revision information to be returned, however that returns
>>>> revision information of the document BEFORE being updated by the
>>>> update function.  So it actually always returns a previous revision
>>>> and not the latest revision.
>>>>
>>>> Is it possible for the update function to return the latest revision
>>>> information or will I have to get this from a separate query after
>>>> updating the document with the update function?
>>>>
>>
> 

Re: CouchDB: Returning latest revision as update function result

Posted by Stanley Iriele <si...@gmail.com>.
No sadly there isn't and that is by design.

In the city text of an update handler you only have the doc before it gets
persisted to disk so you don't know the new revision till afterwards
On Dec 30, 2013 3:36 PM, "Hank Knight" <hk...@gmail.com> wrote:

> Thanks.  Accessing the headers is better than nothing but is there any
> way to get the revision information returned like this?
> return [doc, doc._rev]
>
> On Mon, Dec 30, 2013 at 4:17 PM, Stanley Iriele <si...@gmail.com>
> wrote:
> > Yes...the new ID and rev are returned as headers.
> >
> > X-Couch-Id is the  new ID
> > X-Couch-Update-Newrev is the new revision
> >
> > Here's where its mentioned in the docs
> >
> >
> http://docs.couchdb.org/en/latest/api/ddoc/render.html?highlight=update#put--db-_design-ddoc-_update-func-docid
> > On Dec 30, 2013 3:11 PM, "Hank Knight" <hk...@gmail.com> wrote:
> >
> >> I use this in my update function:
> >> return [doc, doc._rev]
> >>
> >> When a document is updated using the update function, I want the
> >> latest revision information to be returned, however that returns
> >> revision information of the document BEFORE being updated by the
> >> update function.  So it actually always returns a previous revision
> >> and not the latest revision.
> >>
> >> Is it possible for the update function to return the latest revision
> >> information or will I have to get this from a separate query after
> >> updating the document with the update function?
> >>
>

Re: CouchDB: Returning latest revision as update function result

Posted by Hank Knight <hk...@gmail.com>.
Thanks.  Accessing the headers is better than nothing but is there any
way to get the revision information returned like this?
return [doc, doc._rev]

On Mon, Dec 30, 2013 at 4:17 PM, Stanley Iriele <si...@gmail.com> wrote:
> Yes...the new ID and rev are returned as headers.
>
> X-Couch-Id is the  new ID
> X-Couch-Update-Newrev is the new revision
>
> Here's where its mentioned in the docs
>
> http://docs.couchdb.org/en/latest/api/ddoc/render.html?highlight=update#put--db-_design-ddoc-_update-func-docid
> On Dec 30, 2013 3:11 PM, "Hank Knight" <hk...@gmail.com> wrote:
>
>> I use this in my update function:
>> return [doc, doc._rev]
>>
>> When a document is updated using the update function, I want the
>> latest revision information to be returned, however that returns
>> revision information of the document BEFORE being updated by the
>> update function.  So it actually always returns a previous revision
>> and not the latest revision.
>>
>> Is it possible for the update function to return the latest revision
>> information or will I have to get this from a separate query after
>> updating the document with the update function?
>>

Re: CouchDB: Returning latest revision as update function result

Posted by Stanley Iriele <si...@gmail.com>.
Yes...the new ID and rev are returned as headers.

X-Couch-Id is the  new ID
X-Couch-Update-Newrev is the new revision

Here's where its mentioned in the docs

http://docs.couchdb.org/en/latest/api/ddoc/render.html?highlight=update#put--db-_design-ddoc-_update-func-docid
On Dec 30, 2013 3:11 PM, "Hank Knight" <hk...@gmail.com> wrote:

> I use this in my update function:
> return [doc, doc._rev]
>
> When a document is updated using the update function, I want the
> latest revision information to be returned, however that returns
> revision information of the document BEFORE being updated by the
> update function.  So it actually always returns a previous revision
> and not the latest revision.
>
> Is it possible for the update function to return the latest revision
> information or will I have to get this from a separate query after
> updating the document with the update function?
>