Reputation: 137
Following: CouchDB Document Update Handlers (in-place updates) and http://wiki.apache.org/couchdb/Document_Update_Handlers
I'm trying to create my own function which increment an integer for now, but I'm getting:
{"error":"bad_request","reason":"Attachment name can't start with '_'"}
My design document looks like: _design/db
"check": {
"increment": "function(doc,req){ var channel = req.query.channel; doc.channels[0].sp = doc.channels[0].sp+1; return[channel, 'check']}"
}
And the request is like:
curl -X PUT https://server/db/_design/db/_check/increment/channels?channel=foo
I don't understand very well what I'm doing wrong, if I remove the '_' I will get:
{"error":"conflict","reason":"Document update conflict."}
Thanks
Upvotes: 2
Views: 2008
Reputation: 11731
Your request is wrong, I think. Try something like this:
curl -X PUT https://server/db/_design/db/_update/increment/channels?channel=foo
Second, your update handler function should be in an "updates" key directly in the design document (so not as part of any view). So your design document should look like this:
{
"_id": "_design/doc",
"updates": {
"increment": "function(doc,req){ var channel = req.query.channel; doc.channels[0].sp = doc.channels[0].sp+1; return[channel, 'check']}"
}
}
Upvotes: 3