0
votes

Im trying to update a parameter in a collection of objects using Rails, CouchRest.

This is what im doing currently,

class User
   property :country
   property :some_flag
end

@users = User.by_country(:key => 'country-name')
@users.each do |user|
  user.update_attributes({:some_flag => 'true'})
end

Whenever update_attributes failed for a User object i want the entire transaction to be rolled back. How can i achieve this?

Am Using CouchDB. Rails, CouchRest and Not using ActiveRecord.

1

1 Answers

0
votes

CouchDB doesn't explicitly support transaction, but there is something called "bulk update" which may be of help:

http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API#Modify_Multiple_Documents_With_a_Single_Request

Example data for the update:

{
  "all_or_nothing": true,
  "docs": [
    {"_id": "0", "_rev": "1-62657917", "integer": 10, "string": "10"},
    {"_id": "1", "_rev": "2-1579510027", "integer": 2, "string": "2"},
    {"_id": "2", "_rev": "2-3978456339", "integer": 3, "string": "3"}
  ]
}