سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top