如何导出/转储 mongodb 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11041614/
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:41:58  来源:igfitidea点击:

How do I export/dump mongodb database?

mongodbimport

提问by user1052073

I tried a mongo export like this:

我尝试了这样的 mongo 导出:

./mongodump --db local --collection lecturer 

and then I tried:

然后我试过:

./mongodump --db  local --collection posts --out - >  lecturer .csv  

and I get the same error message: Syntax Error: syntax error (shell):1

我收到相同的错误消息: Syntax Error: syntax error (shell):1

  1. What's wrong with my code?
  2. Where is the data stored if export successfully?
  1. 我的代码有什么问题?
  2. 导出成功后数据存放在哪里?

回答by Sergio Tulentsev

mongodumpis a command-line utility and it's supposed to be run from the system command prompt, not the mongo javascript shell.

mongodump是一个命令行实用程序,它应该从系统命令提示符运行,而不是 mongo javascript shell。

./mongodump --db local --collection lecturer

if successful, this command will create some files under dumpdirectory in the current dir.

如果成功,此命令将dump在当前目录的目录下创建一些文件。

回答by krishna

How to backup and restore databases

如何备份和恢复数据库

Start Mongo, open a new tab in terminal. First navigate to the folder where you want to save the backup, then type the following command.

启动 Mongo,在终端中打开一个新选项卡。首先导航到要保存备份的文件夹,然后键入以下命令。

Backup single database:

备份单个数据库:

mongodump --host localhost --port 27017 --db db_name

Restore single database:

恢复单个数据库:

mongorestore --host localhost --port 27017 --db **** dump/db_name

(In this case, ****represents any name for the database)

(在这种情况下,****代表数据库的任何名称)

Backup all databases:

备份所有数据库:

mongodump --host localhost --port 27017

Restore all databases:

恢复所有数据库:

mongorestore --host localhost --port 27017  dump