Lukasz Kujawa
Lukasz Kujawa

Reputation: 3096

CouchDB bulk update based on document values

I would like to update all documents where doc.type = "article".

From what I understand _bulk_docs works on all documents. To narrow down affected docs one can use key value/range.

This is not ideal because I have different types of documents in database. I hoped I can update all documents returned by a view but it seams to be not possible (please correct me if I'm wrong).

The only solution I can think of is prefixing all keys with document type but is that a reasonable approach?

Upvotes: 0

Views: 220

Answers (2)

Stefan Kögl
Stefan Kögl

Reputation: 4743

You could

  • fetch all documents where doc.type == "article" -- you'd probably use a view for this
  • make all modifications locally
  • upload all documents using _bulk_docs

If the number of documents matching your criterion are too large to fit in a single request, you'd have to make multiple requests to _bulk_docs. Also doing this could introduce conflicts that you'd have to resolve afterwards.

Upvotes: 1

vkurchatkin
vkurchatkin

Reputation: 13570

There is no way of doing this in CouchDB. Moreover, there is not much sense in doing this, since in CouchDB you can only update whole document, not just some properties. So if you is was possible to achieve what you want, it would make all the documents identical.

Upvotes: 2

Related Questions