I'm playing around with node.js and streams trying to dump an entire mongoDB collection to a file but it isn't working. I suspect it has something to do with old style streams and 0.10 streams but I could be wrong.
The code below can also be found here: github.com
mongodb-collection-dump
is in that repo as well.
var fs = require('fs');
var dump = require('mongodb-collection-dump');
var collectionDumpFile = '/tmp/collection-dump.json';
var f = fs.createWriteStream(collectionDumpFile);
f.on('open', function() {
var d = dump('mongodb://127.0.0.1/test_db', 'testcollection', f);
});
d.on('end', function(){
console.log("done in write");
});
d.on('error', function(err){
console.log("there was an error");
console.log(err);
});