I have developed an updates handler in CouchDB with test code like this (before inserting into Couch I am removing newlines):
function (doc, req) {
if (req['userCtx']['roles'].indexOf('editor') < 0) {
return [null, 'Access denied'];
}
if (!doc) {
if (/*!('_id' in req) &&*/ !req['_id'] /*&& 'title' in req['body']*/ && !!req['body']['title'] /*&& 'content' in req['body']*/ && !!req['body']['content']) {
return [{ 'title': req['body']['title'], 'content': req['body']['content'], 'date': new Date(), 'edited_by': req['userCtx']['name'] }, 'Created' + toJSON(req)];
}
return [null, 'Empty' + toJSON({ 'no_id': !req['_id'], 'title': !!req['body']['title'], 'content': !!req.body['\"content\"'], 'body':req.body })];
}
doc['date'] = new Date();
doc['edited_by'] = req['userCtx']['name'];
return [doc, 'Edited' + toJSON(doc)];
}
Angular sends data in a POST call
{"title":"test","content":"test"}
However, I am receiving the following response:
Empty{"no_id":true,"title":false,"content":false,"body":"{\"title\":\"test\",\"content\":\"test\"}"}
I am puzzled by why it does not recognize the received object in various formats like direct a.b
, hash a['b']
, or even escaped a['\"b\"']
. I am hoping that this is my mistake and not an issue with CouchDB. How can I rectify this?