No description, website, or topics provided.
CoffeeScript Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Just a Q&D converter, BSON→JSON, and rudimentary schema analysis, for preparing to migrate a MongoDB dump to LevelDB.

Keywords: streams, BSON, JSON, NoSQL, scrubbing, CoffeeScript.


BSON dump files are just concatenated serialized objects. BSON format is amenable to efficient streaming, so we just iterate over the "records" by piping a standard file/stream into a BSON parser, and stringifying each to JSON:

fs.createReadStream process.argv[2]
.pipe new require 'bson-stream'
.on 'data',(o)->
	console.log JSON.stringify o

EOF and callbacks?

Node guarantees process won't exit before all queued callbacks execute. But…

Multiple files

Out of laziness — quick & dirty, like we said — just looped over all files with a shell script:

for f in *.bson
do ./ $f > ${f%.bson}.json

So files are processed sequentially, synchronously, in command line order (left to right). In a more invested migration script we'll iterate over them recursively. Later.