Ah, got it now. Thanks for reminding me about the update handler feature of
couch. I had totally forgotten about it.
--
Michael Jackson
@mjackson
On Thu, Jan 31, 2013 at 5:02 PM, Mark Hahn m...@hahnca.com wrote:
The doc argument comes from couch, not me. The req is what I provide.
Check
GET the document from CouchDB, change the row appropriately, PUT it back to
CouchDB. All using HTTP. CouchDB will complain about merge problems if the
_rev field does not match, if so, retry.
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
I have an update handler that I use for all updates. You just send the
change to the handler and it reads the doc, updates it, and writes it back,
all in one http request. I can even update items nested in objects and
arrays using a syntax like /a/b/c:newValue. I also support deleting
fields at
I'd be happy if I were wrong, but I don't believe it's possible to do all
that with one HTTP request in CouchDB. The read and the write require at
least two requests, a GET and a PUT as Bradley suggests...
--
Michael Jackson
@mjackson
On Thu, Jan 31, 2013 at 1:48 PM, Mark Hahn m...@hahnca.com
I'd be happy if I were wrong
Then smile. I've been using it for a year.
On Thu, Jan 31, 2013 at 2:43 PM, Michael Jackson mjijack...@gmail.comwrote:
I'd be happy if I were wrong, but I don't believe it's possible to do all
that with one HTTP request in CouchDB. The read and the write
BTW, I am only talking about updates, which is what the OP asked about.
The doc must already exist.
On Thu, Jan 31, 2013 at 2:55 PM, Mark Hahn m...@hahnca.com wrote:
I'd be happy if I were wrong
Then smile. I've been using it for a year.
On Thu, Jan 31, 2013 at 2:43 PM, Michael Jackson
Here is the update handler. As you can see it does what I claimed. Enjoy
...
update: (doc, req) -
postData = JSON.parse req.body
if doc
for k, v of postData
hash = doc
if k[0] is '/'
parts = k.split '/'
for part in parts[1..-2] then hash = (hash[part] ?= {})
k = parts[-1..-1][0]
if v is
Thanks for sharing. :) I had assumed that the OP didn't still have the
original document hanging around in memory, as your doc argument
suggests. Hence the need to GET it before updating.
--
Michael Jackson
@mjackson
On Thu, Jan 31, 2013 at 3:06 PM, Mark Hahn m...@hahnca.com wrote:
Here is