javascript - 500 Internal Server Error from Saving to couchDb -
i trying save document couch database. here code use make call
function splitintoitemsthensenditemstocouch(dumpdoc){ var items = dumpdoc.children[0].children[0].children; for(var = 0; < items.length; i++){ var doc = { "_id":items[i].children[1].textcontent, "_attachments": {"content_type":"text\/plain","data":window.btoa(items[i].outerhtml)}} db.savedoc(doc) } } here example of error log couch while trying save document.
[tue, 07 jul 2015 17:42:19 gmt] [error] [<0.112.0>] function_clause error in http request [tue, 07 jul 2015 17:42:19 gmt] [info] [<0.112.0>] stacktrace: [{couch_doc,'-transfer_fields/2-fun-0-', [{<<"content_type">>,<<"text/plain">>}], [{file,"couch_doc.erl"},{line,227}]}, {lists,map,2,[{file,"lists.erl"},{line,1224}]}, {couch_doc,transfer_fields,2, [{file,"couch_doc.erl"},{line,227}]}, {couch_httpd_db,couch_doc_from_req,3, [{file,"couch_httpd_db.erl"},{line,793}]}, {couch_httpd_db,db_doc_req,3, [{file,"couch_httpd_db.erl"},{line,582}]}, {couch_httpd_db,do_db_req,2, [{file,"couch_httpd_db.erl"},{line,234}]}, {couch_httpd,handle_request_int,5, [{file,"couch_httpd.erl"},{line,318}]}, {mochiweb_http,headers,5, [{file,"mochiweb_http.erl"},{line,94}]}] [tue, 07 jul 2015 17:42:19 gmt] [info] [<0.112.0>] 192.168.1.25 - - put /items4493/c-11034 500 [tue, 07 jul 2015 17:42:19 gmt] [error] [<0.112.0>] httpd 500 error response: {"error":"unknown_error","reason":"function_clause"} i have tried quite few things already, , continue so. if of had similar problem please let me know. little illiterate when comes couch error log. think understand gist of it, maybe not if me make little more sense out of log. thank you!
i lucky debugged pretty fast. following direction of https://wiki.apache.org/couchdb/http_document_api#inline_attachments realised made silly mistake. forgot name attached file itself. revise line
var doc = { "_id":items[i].children[1].textcontent, "_attachments": {"content_type":"text\/plain","data":window.btoa(items[i].outerhtml)}} into
var doc = {"_id":items[0].children[1].textcontent, "_attachments": {"items_metadata":{"content_type":"text\/plain","data":window.btoa(items[0].outerhtml)}}}
Comments
Post a Comment