Thursday, April 18, 2013

How to invoke update handler with Cradle?

Invoking an update handler via a Cradle nodejs client should be a simple task but I felt like I spent 10 minutes too many, piecing together documentation on it, since its not explicitly documented in the README.md file.

Based on the comments in the pull request where this functionality was added, here's a sample:
// Let's say you want the client to invoke the equivalent of following URL request:
// https://my.iriscouch.com/db_name/_design/my_design_doc/_update/my_handler/my_doc_id?field=title&value=test
// You would do this via Cradle like so:
var db = adminConnection.database('db_name');
vendDB.update(
'my_design_doc/my_handler',
my_doc_id,
{
'title': 'test'
},
function (err, res) {
if (err) {
console.error(err);
} else {
console.log(res);
}
}
);

0 comments:

Post a Comment