I’m trying to update and array passing a json object or variables and build the json in the function. Which is the best way to do it?
For example, the function which I use to send variables and build the json:
function(doc,req){
var name = req.query.name;
var number = req.query.number;
var channel = {"name":"" , "number" : ""};
channel.name = name;
channel.number = number;
doc.channels.push(channel);
return[doc, channel + ' added'];}
curl -X PUT https://server/db/_design/doc/_update/addChannel/channels?name=myChannel&number=23
But what I got is just this in the array:
{
"name": "myChannel"
}
Why the second variable is not there?
Is it possible to pass a json object in the url like : channels?json={}… ??
Thanks
I suspect you forgot to enclose the url in single quotes. The presence of the & indicates to your shell that it should run the command in the background (and the ‘number=23’ part is simply ignored).
try;
and I suspect it will work.
I’ll also note that the function could be written more simply as;
Note that the “23” will be passed as a string, so I added a parseInt call also.