How do I export/dump mongodb database?

2019-01-17 01:29发布

I tried a mongo export like this:

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

  1. What's wrong with my code?
  2. Where is the data stored if export successfully?

2条回答
啃猪蹄的小仙女
2楼-- · 2019-01-17 02:09

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.

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
查看更多
等我变得足够好
3楼-- · 2019-01-17 02:20

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

./mongodump --db local --collection lecturer

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

查看更多
登录 后发表回答