Ah, this is obviously some way of self documenting that I wasn't previously aware of.
;-)) Thank you Martin & Greetings from Hamburg, alux On 28 July 2010 10:38, Martin Higham <mar...@ocasta.co.uk> wrote: > I was simply looking at the couchdb log (debug level) for some other > information in the request object and saw "uuid". > > On 28 July 2010 09:29, Alux <alu...@googlemail.com> wrote: > > > Ah, thats pretty! > > > > Many thanks Martin, that makes it feel much more couchy! > > > > How did you discover that? I'm very impressed! > > > > Thanks again, and nice day, > > > > alux > > > > > > On 28 July 2010 10:21, Martin Higham <mar...@ocasta.co.uk> wrote: > > > > > I had the same problem and was about to embark on a similar solution > when > > I > > > discovered that the req object passed into the update handler contains > a > > > uuid for you to use. So all you need to do is > > > > > > function(doc, req) { > > > var newDoc = JSON.parse(req.body); > > > if (!doc){ > > > newDoc._id = req.uuid; > > > ... > > > > > > > > > Martin > > > > > > > > > > > > On 28 July 2010 09:01, Alux <alu...@googlemail.com> wrote: > > > > > > > Hello, > > > > > > > > after some funny result I now am able to create documents with an > > update > > > > handler. I want to use usual couchy ids, and didnt know how to get > the > > > (in > > > > one step, that is), so I did created one in JavaScript as below. Is > > this > > > > sensible? I'm a newbee, so comments are very welcome. > > > > > > > > Kind regards, alux > > > > > > > > ------ > > > > > > > > function(doc, req) { > > > > start({'headers': {'Content-Type': 'text/html'}}); > > > > var maxStr = 'ffffffffff'; > > > > var max = parseInt(maxStr, 16); > > > > var r1=Math.floor(Math.random()*max); > > > > var r2=Math.floor(Math.random()*max); > > > > var r3=Math.floor(Math.random()*max); > > > > var r4=Math.floor(Math.random()*max); > > > > var rstr = r1.toString(16) + r2.toString(16) + > > r3.toString(16) > > > + > > > > r4.toString(16); > > > > var id = rstr.substr(0,32); > > > > doc = {_id: id}; > > > > doc.type = 'note'; > > > > var message = '<html><body><h3>Created new document with > > id=' > > > + > > > > id + '</h3>' + > > > > '<a href=\'' +id+ '\'>Enter the new > > > > document.</a></body></html>'; > > > > return [doc, message]; > > > > } > > > > > > > > Remarks: > > > > > > > > 1. This update handler shall be called from a browser with HTTP POST > > from > > > a > > > > form, it returns HTML for the browser. > > > > 2. The four steps of random generation are because Math.random > > generates > > > > not > > > > very long numbers, and toString() removes leading zeros. So this > should > > > be > > > > rather safe. > > > > > > > > > >