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.
The mongorestore utility restores a binary backup created by mongodump . By default, mongorestore looks for a database backup in the dump/ directory. The mongorestore utility restores data by connecting to a running mongod directly. mongorestore can restore either an entire database backup or a subset of the backup.
By default, mongorestore looks for a database backup in mongodb's bin\dump folder which is also the default folder for mongodump command for dumping the backup. Example: In this example, we are using a database GeeksForGeeks which has 4 collections.
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.
Dump DB by mongodump
mongodump --host <database-host> -d <database-name> --port <database-port> --out directory
Restore DB by mongorestore
With Index Restore
mongorestore --host <database-host> -d <database-name> --port <database-port> foldername
Without Index Restore
mongorestore --noIndexRestore --host <database-host> -d <database-name> --port <database-port> foldername
Import Single Collection from CSV [1st Column will be treat as Col/Key Name]
mongoimport --db <database-name> --port <database-port> --collection <collection-name> --type csv --headerline --file /path/to/myfile.csv
Import Single Collection from JSON
mongoimport --db <database-name> --port <database-port> --collection <collection-name> --file input.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With