What would be the easiest way to import with mgo?
Easiest? Shell out to mongorestore
from your go program. Boom, done.
Does mgo support inserting a backed-up BSON collection?
I don't see any first-class support for it. (You could email the author). It should be possible, but it may be a bit of work. You should be able to use the mgo BSON layer to load the *.bson
files and insert them into the DB. But you'll also have to parse the *.metadata.json
files for the indexes, etc. It seems like a lot of work. (basically rewriting mongorestore
.)
Or do I need to use the JSON export, unmarshal it and then do insert() with mgo?
That would be slower, and you'd have to test that $date
and $oid
are handled correctly, but it seems like it should work. It might even be simpler to write because you don't have to learn the BSON layer.