Skip to content

Instantly share code, notes, and snippets.

@jo
Created August 3, 2012 13:05
Show Gist options
  • Save jo/3247561 to your computer and use it in GitHub Desktop.
Save jo/3247561 to your computer and use it in GitHub Desktop.
A CouchDB Worker that fetches a remote JSON and inserts it into a document.
/*
* CouchDB Worker Fetch JSON
*
* A CouchDB Worker that fetches a remote JSON and inserts it into a document.
*
* Author: Johannes J. Schmidt
* (c) null2 GmbH, 2012
* MIT Licensed
*/
var Worker = require("couchdb-worker");
var request = require("request");
var util = require("util");
new Worker.pool({
name: 'fetch-json',
server: process.env.COUCHDB_SERVER || "http://localhost:5984",
processor: {
check: function(doc) {
return doc._id.match(/^\d+$/);
},
process: function(doc, done) {
request({
url: util.format(this.config.url, doc._id),
json: true
}, function(error, resp, data) {
done(error, data);
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment