Bulk updating a CouchDB database without a _rev value per document?
According to the CouchDB Wiki on PUT operations.
To update an existing document, you 开发者_如何学Pythonalso issue a PUT request. In this case, the JSON body must contain a _rev property, which lets CouchDB know which revision the edits are based on. If the revision of the document currently stored in the database doesn't match, then a 409 conflict error is returned.
My goal is to perform a bulk_docs update:
curl -X POST [domain]/[couch db name]/_bulk_docs -H "Content-type: application/json" -d @[some document].json
My workflow is like this:
- My data is in an Google Docs spreadsheet.
- I convert the spreadsheet data to JSON by copying and pasting into Mr. Data Converter
- I use cURL (as show above) to add/update documents
The problem is that the first time I add new documents, everything works perfectly, however the next time I post the same documents, I get following error for each document:
...{"id":"28"," error":"conflict","reason":"Document update conflict."}...
Is there any way to update an existing document without including a _rev property?
By design, you cannot update a CouchDB document blindly, you can only attempt to update a specific revision of a document.
For a single document, you can use a CouchDB update handler to hide this from the client as an update handler will be passed the existing document (if it exists) including its revision.
For a collection of documents, when using _bulk_docs
, you can add "new_edits": false
which will forcibly insert conflicts instead of rejection (though you'll still need to pass a _rev, it just doesn't have to be the current one).
All that said, it would be better to follow the rules. Grab the current revision of the document you would like to update, attempt to update it, if you get a 409, get the new version, merge as appropriate, and update again.
精彩评论