Mongodb's "mongodump" command, javascript execution error
Asked Answered
L

3

9

Perhaps I have a complete misunderstanding of how mongodump is supposed to work, but I can't seem to get it to do anything besides returning a JavaScript execution failed: SyntaxError: Unexpected identifier error.

Here's what I'm doing:

  • Mongod is running
  • I want to backup a database called "mydb"
  • I'm inside the mongo shell
  • I tried the command mongodump --db mydb and get the above error
  • I've tried both mongodump and mongoexport, both have the same issue

What am I doing wrong here?

Lengel answered 25/7, 2013 at 5:39 Comment(0)
J
23

Try the following it will work

i.Open the terminal

ii. Enter mongodump --collection collectionname --db dbname (Don't go inside mongo shell);

iii.If default port is different(other than 27017) then go for the following command

   mongodump --host mongodb1.example.net --port 37017 --username user --password pass    --out /opt/backup/mongodump-2011-10-24
Jerboa answered 25/7, 2013 at 5:45 Comment(2)
Ah, didn't realise you're meant to do it from outside of mongoDb. Makes sense, got it working!Lengel
You can add the port to the host and use -o for output: mongodump --host mongodb1.example.net:37017 -o /opt/backup/mongodump-2011-10-24Reprobate
P
5

mongodump,mongorestore is not commands of mongodb shell. It is separate mongodb utlity. You can find it under mongodb bin folder.

Usually you will need to add all mongodb utilities to the system Path variable and after this easy backup/restore databases from any place in the command line or in the terminal.

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

Pedestrian answered 25/7, 2013 at 5:45 Comment(0)
M
3

I faced the problem in taking mongo dump and I also wanted to store the dump to S3. Finally I ended up with a bash script to take mongo dump and store it to S3. I used mongodump to take backup.

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

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

Manassas answered 13/3, 2016 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.