Skip to content

Instantly share code, notes, and snippets.

@ejeklint
Created August 16, 2013 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejeklint/6252075 to your computer and use it in GitHub Desktop.
Save ejeklint/6252075 to your computer and use it in GitHub Desktop.
var nano = require('nano')('http://blablabla/');
String.prototype.toUnderscore = function(){
return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();});
};
// For all meetings
nano.db.list(function(err, body) {
body.forEach(function(db) {
if (!db.match(/meeting\//)) {
return;
}
console.log('patching db: ' + db);
var this_db = nano.use(db)
// For all docs
this_db.list({include_docs: true}, function(err, body) {
if (!err) {
body.rows.forEach(function(doc) {
var the_doc = doc.doc;
// For all properties
for (var property in the_doc) {
if (the_doc.hasOwnProperty(property)) {
// Do snake charming
var snake_charmed = property.toUnderscore();
if (snake_charmed !== property) {
the_doc[snake_charmed] = the_doc[property];
delete the_doc[property];
}
}
}
this_db.insert(the_doc, function(err, body) {
if (err) console.log(err);
});
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment