使用mGo导入备份集合

I have a BSON export from mongodump, and I also have a JSON export for mongoexport

What would be the easiest way to import with mgo? Does mgo support inserting a backed-up BSON collection?

Or do I need to use the JSON export, unmarshal it and then do insert() with mgo?

Thing is that I don't want to have to specify a scheme in my Go file - I just want to dump the file into a database.

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.