Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I export/dump mongodb database?

Tags:

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?
like image 877
user1052073 Avatar asked Jun 14 '12 21:06

user1052073


People also ask

Where is MongoDB dump folder?

By default, mongorestore looks for a database backup in mongodb's bin\dump folder which is also the default folder for mongodump command for dumping the backup. Example: In this example, we are using a database GeeksForGeeks which has 4 collections.

How do I export and import MongoDB database?

Choose a file type and export location.Under Select Export File Type, select either JSON or CSV. If you select JSON, your data is exported to the target file as a comma-separated array. Then, under Output, choose where to export the file to.


1 Answers

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 UserDefinedName for the database > mydb dump/db_name > this will import dump db into mydb)

Backup all databases:

mongodump --host localhost --port 27017 

Restore all databases:

mongorestore --host localhost --port 27017  dump 
like image 107
krishna Avatar answered Sep 22 '22 13:09

krishna