Skip to content

Instantly share code, notes, and snippets.

@natevw
Created May 24, 2012 20:11
Show Gist options
  • Save natevw/2783929 to your computer and use it in GitHub Desktop.
Save natevw/2783929 to your computer and use it in GitHub Desktop.
2couchbase2 - dump everything from CouchDB into Couchbase (via memcached interface)
var asy = require('async'),
mc = require('mc'),
f = require('fermata');
var DB = 'test';
var client = new mc.Client(),
source = f.json("http://localhost:5984")(DB);
var page = {limit:5};
function nextSet() {
source._all_docs({include_docs:true})(page).get(function (e,d) {
//var rowsToCopy = d.rows.filter(function (r) { return (r.id[0] !== '_'); }); // filter out design docs
var rowsToCopy = d.rows;
if (d.rows.length) asy.forEach(rowsToCopy,
function (r, cb) {
delete r.doc._id;
delete r.doc._rev;
client.set(r.id.replace(/ /g,''), JSON.stringify(r.doc), cb);
},
function (err) {
console.log((err) ? "FAILED" : "Copied", rowsToCopy.map(function (r) { return r.id; }).join(' '));
if (err) throw JSON.stringify(err);
page['$startkey'] = d.rows[d.rows.length - 1].key;
page.skip = 1;
nextSet();
}
); else {
console.log("All finished.");
client.disconnect();
return;
}
});
}
client.connect(function() {
console.log("Connected");
nextSet();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment