You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Jim Garvin <ji...@thegarvin.com> on 2010/03/02 22:53:16 UTC

Setting document _id in _update handler

Hi again,

Does anyone know a server-side workaround for this
bug<https://issues.apache.org/jira/browse/COUCHDB-645>
?

Apparently if you use an _update handler for creating a document you are
responsible for the _id because CouchDB won't set it to a UUID if you just
leave it undefined. :'(

Here's my update handler for reference:

function(doc, req) {
  var newDoc = JSON.parse(req.body);
  newDoc.created_at = (new Date()).getTime();
  // newDoc._id = "is there a function I can call here to generate a UUID?";
  return [newDoc, "ok"];
}

Thanks,
Jim

Re: Setting document _id in _update handler

Posted by Jim Garvin <co...@gmail.com>.
Done, thanks.

On Sat, Mar 6, 2010 at 7:49 AM, Sebastian Cohnen <
sebastiancohnen@googlemail.com> wrote:

> On 06.03.2010, at 08:58, Jim Garvin wrote:
>
> > Here's a fix for COUCHDB-645<
> http://issues.apache.org/jira/browse/COUCHDB-645>
> > :
> >
> >
> http://github.com/coderifous/couchdb/tree/updates_handler_fix_COUCHDB_645
> >
> > Is there a process for submitting patches?
>
> Upload them to JIRA :)
>
>
>

Re: Setting document _id in _update handler

Posted by Sebastian Cohnen <se...@googlemail.com>.
On 06.03.2010, at 08:58, Jim Garvin wrote:

> Here's a fix for COUCHDB-645<http://issues.apache.org/jira/browse/COUCHDB-645>
> :
> 
> http://github.com/coderifous/couchdb/tree/updates_handler_fix_COUCHDB_645
> 
> Is there a process for submitting patches?

Upload them to JIRA :)



Re: Setting document _id in _update handler

Posted by Jim Garvin <ji...@thegarvin.com>.
Here's a fix for COUCHDB-645<http://issues.apache.org/jira/browse/COUCHDB-645>
:

http://github.com/coderifous/couchdb/tree/updates_handler_fix_COUCHDB_645

Is there a process for submitting patches?

Regards,
Jim


On Tue, Mar 2, 2010 at 5:38 PM, Jim Garvin <ji...@thegarvin.com> wrote:

> I've got a patch coming for this.  Just need to write tests for it.  First
> contribution!  *woot*
>
>
> On Tue, Mar 2, 2010 at 4:53 PM, Jim Garvin <ji...@thegarvin.com> wrote:
>
>> Hi again,
>>
>> Does anyone know a server-side workaround for this bug<https://issues.apache.org/jira/browse/COUCHDB-645>
>> ?
>>
>> Apparently if you use an _update handler for creating a document you are
>> responsible for the _id because CouchDB won't set it to a UUID if you just
>> leave it undefined. :'(
>>
>> Here's my update handler for reference:
>>
>> function(doc, req) {
>>   var newDoc = JSON.parse(req.body);
>>   newDoc.created_at = (new Date()).getTime();
>>   // newDoc._id = "is there a function I can call here to generate a
>> UUID?";
>>   return [newDoc, "ok"];
>> }
>>
>> Thanks,
>> Jim
>>
>>
>>
>

Re: Setting document _id in _update handler

Posted by Jim Garvin <ji...@thegarvin.com>.
I've got a patch coming for this.  Just need to write tests for it.  First
contribution!  *woot*


On Tue, Mar 2, 2010 at 4:53 PM, Jim Garvin <ji...@thegarvin.com> wrote:

> Hi again,
>
> Does anyone know a server-side workaround for this bug<https://issues.apache.org/jira/browse/COUCHDB-645>
> ?
>
> Apparently if you use an _update handler for creating a document you are
> responsible for the _id because CouchDB won't set it to a UUID if you just
> leave it undefined. :'(
>
> Here's my update handler for reference:
>
> function(doc, req) {
>   var newDoc = JSON.parse(req.body);
>   newDoc.created_at = (new Date()).getTime();
>   // newDoc._id = "is there a function I can call here to generate a
> UUID?";
>   return [newDoc, "ok"];
> }
>
> Thanks,
> Jim
>
>
>