How to restore the dump into your running mongodb

Sandeep Singh picture Sandeep Singh · Sep 21, 2013 · Viewed 119.4k times · Source

I want to load data/restore dump data in mongoDB using mongorestore. I am trying to command

mongorestore dump

but it giving me error

Sat Sep 21 16:12:33.403 JavaScript execution failed: SyntaxError: Unexpected identifier

How can we restore or put data into mongoDB?? Please give me the steps.

Answer

Arman Ortega picture Arman Ortega · Jan 20, 2015

mongodump: To dump all the records:

mongodump --db databasename

To limit the amount of data included in the database dump, you can specify --db and --collection as options to mongodump. For example:

mongodump --collection myCollection --db test

This operation creates a dump of the collection named myCollection from the database 'test' in a dump/ subdirectory of the current working directory. NOTE: mongodump overwrites output files if they exist in the backup data folder.


mongorestore: To restore all data to the original database:

1) mongorestore --verbose \path\dump

or restore to a new database:

2) mongorestore --db databasename --verbose \path\dump\<dumpfolder>

Note: Both requires mongod instances.