I want to use an existing Couchdb document, to deep-merge some data on this request
Request::
curl -H "Content-Type: application/json" -X POST http://localhost/couch/ddb/_design/data/_update/push2/cap1 -d '{"51" : 5, "65" : 2}'
Database Document::
{65: [[]], 51: [[]]};
Update function::
function(doc, req) {
var d = req.body;
for(var key in doc.x2) {
doc.x2[key][0].push(d[key]);
};
return [doc,'added'];}"
The problem is that req.body
that contains the data shows up as String
not as a JSON object
making it impossible to select the value
The result to the query should be::
{65: [[2]], 51: [[5]]};
Everthing else works fine, expect req.body
is a String
and not an Object
Well, found my own answer. Wasn't hard:
var d = req.body;
>> var d = JSON.parse(req.body);
and d
becomes Object