
A few days ago I wrote my first Node.js tool. I wrote it only partly for myself, because for me it is not very relevant yet, but for some people it very much is.
The tool is for CouchDB. Since CouchDB keeps document revisions after changes and deletions and does not always clean them up, a database can grow like crazy. For example, for the guys who need this tool right now, something that should weigh 6 GB weighs 50-60. Maybe they started something somewhere or messed something up, changed and wrote a ton of stuff into the database, and that blew up its size. So, overall, it is easier to just create a new clean database and move all live documents there.
The tool simply takes all documents from 1 database in CouchDB and puts them into another one. For now it works rather crudely: it grabs all documents in one shot and then inserts them into the database one by one. For databases with a relatively small number of documents it works fine, but if there are something like 80 thousand documents, fetching them on my computer took about 4-5 minutes. So I will rework it soon so that it pulls documents in batches and writes them to the database sequentially instead of asynchronously.
But it is already usable. You can embed the tool into your own Node.js project, for example.
In the console:
npm install node-couchdb-mover
In code:
var mover = require('node-couchdb-mover');
mover.moveDocuments('dbName1', 'dbName2');
It can also be used directly from the console:
npm install -g node-couchdb-mover
couchdb-mover --from=dbName1 --to=dbName2
And, as expected, here are the sources on GitHub and the package on npmjs.org.