benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 114 forks source link

Adding a function to update a field of a doc #79

Closed Nesh108 closed 10 years ago

Nesh108 commented 12 years ago

As there is a function for deleting a single field of a doc, it would be very useful to have a function for updating just one field.

It would be also interesting to have a similar function which just is used for incrementing the value by a certain amount, for instance:

"counter" = 1

update_field("counter", 1, increment)

"counter" = 2

update_field("counter", 5, increment)

"counter" = 7

update_field("counter", 6, decrement)

"counter" = 1

Nesh108 commented 12 years ago

Any info?

benoitc commented 11 years ago

couchbeam_doc:set_value does that. If you wan't atomic updates of a field in a doc this isn't possible yet with the couchdb api.

Matybe there could be an update function allowing you to walk in a doc and replace values if needed. Would it be useful?

benoitc commented 10 years ago

The module couchbeam_doc already offer a bunch of functions allowing to manipulate the JSON objects. You can, set,delete,extend,fet,or take a value from them. About the latest feature it should be done at app level imo. Though an interresting feature could be adding a way to "patch" a doc.

Anyway closing this issue since most is already addressed.