24

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?
Sergio Tulentsev
  • 219,187
  • 42
  • 361
  • 354
user1052073
  • 479
  • 2
  • 6
  • 10

2 Answers2

41

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
DevCo
  • 329
  • 1
  • 2
  • 15
krishna
  • 689
  • 1
  • 7
  • 6
28

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.

Sergio Tulentsev
  • 219,187
  • 42
  • 361
  • 354
  • 16
    for the mongo clueless like me who came here, replace `local` with the name of the DB you want to export and leave off `--collection` if you want to export the whole db. – Jason Jan 24 '13 at 18:11