Mongodb command "mongodump", javascript runtime error

I may have a complete misunderstanding of how mongodump should work, but I can't get it to do anything except return a JavaScript execution failed: SyntaxError: Unexpected identifier error.

That's what I'm doing:

  • Mongod works
  • I want to back up a database called "mydb"
  • I'm inside the mongo shell
  • I tried the mongodump --db mydb and got the above error
  • I tried both mongodump and mongoexport , both have the same problem

What am I doing wrong here?

+7
mongodb mongodump
source share
3 answers

Try the following: work

i. open a terminal

II. Enter mongodump - collection name of the collection --db dbname (do not go into the mongo shell);

iii. If the default port is different (except 27017), go to the next command

  mongodump --host mongodb1.example.net --port 37017 --username user --password pass --out /opt/backup/mongodump-2011-10-24 
+19
source share

mongodump, mongorestore are not mongodb shell commands. This is a separate mongodb unit. You can find it in the bin mongodb folder.

Usually you need to add all mongodb utilities to the System Path variable and after these simple backups / restore databases from anywhere on the command line or in the terminal.

Your command looks like mongodump --db mydb good if your databases are in the default port (27017).

+4
source share

I ran into a problem while taking a mongo dump, and I also wanted to save the S3 dump. Finally, I got a bash script to take mongo dump and save it to S3. I used mongodump for backup.

 mongodump -h $MONGO_HOST:$MONGO_PORT -d $MONGO_DATABASE 

Where $MONGO_HOST , $MONGO_PORT and $MONGO_DATABASE are the bash variables for host , port and database-name respectively. You can also use the --username user --password pass option for the mongodump command if you have a username and password setting in the database. Here is a script to take a mongodb dump and save it to S3 using cron.

+3
source share

All Articles