CouchDB
To create an update handler, write a design document:
{
"_id": "_design/yourapp",
"updates": {
"foo": "function(doc, req) {
doc.groups.push(req.query.bar); // or do whatever you like with it
return [doc, 'done'];
}"
}
}
and PUT it in your db with the id _design/yourapp
, then GET it like this:
http://localhost:5984/users/_design/yourapp/_update/foo/jim?bar=baz
nanocouch
var dbserv = require('nano')('http://localhost:5984');
var db = dbserv.use('users');
var designdoc = {/* The above design document */};
db.insert(designdoc);
db.get('_design/yourapp/_update/foo/jim', {bar: 'baz'});
Note that you need to insert the design document only once, you can even do it manually using curl
, then to update your docs just make a GET request as explained above.
Disclaimer: untested and I never used nano before, but it should be on the lines of what you have to do.