mongodb 如何导入转储的Mongodb?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8070298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:18:35  来源:igfitidea点击:

How to import dumped Mongodb?

mongodbmongoimportmongorestore

提问by YogiZoli

Dumped a MongoDB successfully:

成功转储 MongoDB:

$ mongodump -h ourhost.com:portnumber -d db_name01 -u username -p

I need to import or export it to a testserver and have struggle with it, please help me figure out.

我需要将它导入或导出到测试服务器并且遇到困难,请帮我弄清楚。

I tried some ways:

我尝试了一些方法:

$ mongoimport -h host.com:port -c dbname -d dbname_test -u username -p
connected to host.
Password: ...

Gives this error:

给出这个错误:

assertion: 9997 auth failed: { errmsg: "auth fails", ok: 0.0 }

$ mongoimport -h host.com:port -d dbname_test -u username -p

Gives this error:

给出这个错误:

no collection specified!

How to specify which collection to use? What should I use for -d? What I'd like to upload or what I want to use as test out there? I would like to import the full DB not only collection of it.

如何指定使用哪个集合?-d 我应该用什么?我想上传什么或我想用什么作为测试?我想导入完整的数据库,而不仅仅是它的集合。

回答by dcrosta

The counterpart to mongodumpis mongorestore(and the counterpart to mongoimportis mongoexport) -- the major difference is in the format of the files created and understood by the tools (dumpand restoreread and write BSONfiles; exportand importdeal with text file formats: JSON, CSV, TSV.

对方给mongodumpmongorestore(以及对应于mongoimportmongoexport) -的主要区别是在创造和理解这些工具中的文件的格式(dumprestore读写BSON文件;exportimport用文本文件格式的交易:JSON,CSV,TSV。

If you've already run mongodump, you should have a directory named dump, with a subdirectory for each database that was dumped, and a file in those directories for each collection. You can then restore this with a command like:

如果您已经运行了mongodump,您应该有一个名为dump的目录,每个转储的数据库都有一个子目录,每个集合在这些目录中都有一个文件。然后,您可以使用以下命令恢复它:

mongorestore -h host.com:port -d dbname_test -u username -p password dump/dbname/

Assuming that you want to put the contents of the database dbnameinto a new database called dbname_test.

假设您要将数据库的内容dbname放入一个名为dbname_test.

回答by Bryan Migliorisi

When you do a mongodumpit will dump in a binary format. You need to use mongorestoreto "import" this data.

当您执行 a 时mongodump,它将以二进制格式转储。您需要使用mongorestore来“导入”这些数据。

Mongoimportis for importing data that was exported using mongoexport

Mongoimport用于导入使用导出的数据 mongoexport

回答by Ricky

You may have to specify the authentication database

您可能必须指定身份验证数据库

mongoimport -h localhost:27017 --authenticationDatabase admin -u user -p -d database -c collection --type csv --headerline --file awesomedata.csv