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.
Permalink
Failed to load latest commit information.
.gitignore
README.md
b2j-all.sh
bson-schema.coffee
bson2json.coffee
package.json

README.md

bson2json

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→JSON

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:

#!/bin/sh
for f in *.bson
do ./bson2json.coffee $f > ${f%.bson}.json
done

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.