3

I'm using CouchDB and I have a situation where there are a bunch of documents keyed on user ids. I would like to be able to send a single query to update a particular field in all these documents. For example when a notification comes in, I'd like each user document to be updated with it by passing in the list of users to whom the notification applies and the notification message.

Yogthos
  • 311
  • 3
  • 10

2 Answers2

8

Sadly the _update handlers in CouchDB currently only support a single document at a time, so it's not possible to use an _update handler on multiple documents. For this, you'd need to build a small "proxy," server-side script that would receive the request and send individual _update handler requests one per document. Not ideal, but until there's a patch to allow bulk update handlers to be built, this is the way to go.

I've requested a _bulk_update handler (or similar) be added to a future version of CouchDB...as I'd like the feature as well. :) https://issues.apache.org/jira/browse/COUCHDB-1303

BigBlueHat
  • 2,355
  • 25
  • 30
3

I'd read _changes (probably apply a filter) and then execute the HTTP queries needed.

Keep in mind that you'll need to fetch the document, before updating it.

Till
  • 22,236
  • 4
  • 59
  • 89
  • 1
    Well I saw this example http://stackoverflow.com/questions/2972068/couchdb-document-update-handlers-in-place-updates on how to use update handlers, it seems like it should be possible to setup a script on the server to do the work, which would avoid passing the documents back and forth. – Yogthos Nov 01 '10 at 14:51