使用mGo导入备份集合

huangapple go评论84阅读模式
英文:

Importing Backup Collections with mGo

问题

我有一个来自mongodump的BSON导出文件,还有一个mongoexport的JSON导出文件。

使用mgo导入的最简单的方法是什么?mgo是否支持插入备份的BSON集合?

还是说我需要使用JSON导出文件,进行解组(unmarshal),然后使用mgo的insert()方法?

问题是我不想在我的Go文件中指定模式(scheme),我只想将文件转储到数据库中。

英文:

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.

答案1

得分: 1

导入 mgo 的最简单方法是什么?

最简单的方法是从你的 Go 程序中调用 mongorestore。搞定!

mgo 支持插入备份的 BSON 集合吗?

我没有看到它有一流的支持。(你可以给作者发电子邮件)。理论上是可以的,但可能需要一些工作。你应该能够使用 mgo 的 BSON 层加载 *.bson 文件并将其插入到数据库中。但你还需要解析 *.metadata.json 文件中的索引等信息。这似乎是一项很大的工作。(基本上是重写 mongorestore。)

还是我需要使用 JSON 导出,解组它,然后使用 mgo 进行插入操作?

那样会更慢,并且你需要测试 $date$oid 是否被正确处理,但看起来应该可以工作。甚至可能更简单,因为你不需要学习 BSON 层。

英文:

> 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.

huangapple
  • 本文由 发表于 2014年4月7日 03:03:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/22898557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定