Is there any way in couchdb to update all documents matching certain conditions? (e.g. create new fields and set values to something based on other data in the document)
I realize that if "new" data can be functionally derived from existing data, then technically you can accomplish this via new views w/o changing the documents, but I need to update a few thousand documents with essentially the same operation.
To update large set of documents, use Bulk Write operations. The Java client (uses MongoDB Java Driver) code you write and execute submits the update query to the server, the update happens on the server and you get the result (status, number of documents updated, etc.) back at the Java client.
To update multiple documents, use db. collection. updateMany()
Update all fields in a documentPress Ctrl + A. Press F9. If your document has tables with fields or formulas, you might need to select each table separately and press F9.
Update Multiple Fields of a Single Document. We can use $set and $inc operators to update any field in MongoDB. The $set operator will set the newly specified value while the $inc operator will increase the value by a specified value.
You can use the bulk docs api: http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API but you will need to have all the docs first, and submit them back.
or a doc update handler: http://wiki.apache.org/couchdb/Document_Update_Handlers but you at least need to know a list of doc ids, and do one request per id.
Either way, there is nothing like sql where you can issue an update/where statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With