Mark Hahn <mark@...> writes:
>
> I'm surprised you could ever change the _id field.
>
> On Mon, Feb 25, 2013 at 8:18 AM, Dominic Laflamme <flamz3d@...> wrote:
>
> > Hello,
> > I am using an update handler to insert new documents.
> >
> > the following works fine in 1.2.0 and 0.10.0, but no longer works in 1.2.1
> >
> >
> > function(doc,req) {
> > var data = JSON.parse(req.body);
> > data[\'_id\'] = data.UniqueID;
> > if ( data.timestamp == null )
> > {
> > data.timestamp = new Date().getTime();
> > }
> > return [ data, JSON.stringify(data)]}");
> >
> >
> > this returns "bad return value".
> >
> > any ideas?
> >
> >
> >
> >
> >
> >
>
Hi Mark,
Yes, I'm creating the _id myself, which, if I am not mistaken, is the
documented
way to create documents from an update handler.
I'm following the documentation found at
http://wiki.apache.org/couchdb/Document_Update_Handlers
which states:
"The handler function takes the most recent version of the document from the
database and the http request environment as parameters. It returns a two-
element array: the first element is the (updated or new) document, which is
committed to the database. If the first element is null no document will be
committed to the database. If you are updating an existing, it should already
have an _id set, and if you are creating a new document, make sure to set its
_id to something, either generated based on the input or the req.uuid provided.
The second element is the response that will be sent back to the caller."
Works on 0.10.0 and 1.2.0 on linux, and 1.2.0 Windows.
Fails on 1.2.1 linux.
—Dominic