I have create a new design documents with a dummy update function. But when I try to test it, CouchDB is not identifying my function in the design document.
Below is my design document:
{
"_id": "_design/payable_draft",
"_rev": "13-c9c9a9f88c24b75cdd28204a526f66a6",
"updates": "{\"empty_update\":\"function(doc, req){\n\treturn [doc,toJSON(\"empty_update\")];\n}\"}"
}
But when I try to invoke this update function using a put, getting 404. Request:
PUT /db/_design/payable_draft/_update/empty_update/my_doc HTTP/1.1
Host: <my couchDB>
Accept: application/json
Content-Type: application/json
Cache-Control: no-cache
Response:
{
"error": "not_found",
"reason": "missing updates function empty_update on design doc _design/payable_draft"
}
I see everything looks fine, not able to find the issue. Any help would be greatly appreciated.
I think your escaping is wrong. Your "updates" block contains one complete string. Try this one:
{
"_id":"_design/payable_draft",
"_rev":"13-c9c9a9f88c24b75cdd28204a526f66a6",
"updates":{
"empty_update" : "function(doc, req){return [doc,toJSON('empty_update')];}"
}
}
See http://wiki.apache.org/couchdb/Document_Update_Handlers for more details. As described there one must place the update handler as attributes below "updates":
"updates" : {
"myhandler" : "function(doc, req) { ... }"
}