How to restore the dump into your running mongodb
Solution 1
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.
Solution 2
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
Solution 3
To restore a single database:
Backup the
testdb
database$ mongodump --db testdb
Restore the
testdb
database to a new database calledtestdb2
$ mongorestore --db testdb2 dump/testdb
To restore all databases:
Backup all databases
$ mongodump
Restore all databases
$ mongorestore dump
Solution 4
The directory should be named 'dump' and this directory should have a directory which contains the .bson and .json files. This directory should be named as your db name.
eg: if your db name is institution then the second directory name should be institution.
After this step, go the directory enclosing the dump folder in the terminal, and run the command
mongorestore --drop.
Do see to it that mongo is up and running.
This should work fine.
Solution 5
Follow this path.
C:\Program Files\MongoDB\Server\4.2\bin
Run the cmd in bin folder and paste the below command
mongorestore --db <name-your-database-want-to-restore-as> <path-of-dumped-database>
For Example:
mongorestore --db testDb D:\Documents\Dump\myDb
Sandeep Singh
Big Data & Hadoop project implementation specialist. Expertise in cost effective Hadoop project implementation, cluster configuration, Hadoop/Spark jobs/applications/cluster performance tuning and memory management, data processing application development, ingestion and transformations.
Updated on July 05, 2022Comments
-
Sandeep Singh almost 2 years
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.
-
Benjamin almost 6 yearsHow to pass the DB credentials when restoring?
-
nicodemus13 over 5 years@Benjamin
mongorestore -u <username> --authenticationDatabase "admin" --db databasename
. Authentication database not necessarily 'admin', but probably. You should be asked for the password interactively (you may also need to elevate with sudo). -
whoami - fakeFaceTrueSoul about 5 yearsYou should be sure before you use --drop in your command cause it will drop the existing collection in the DB and recreate a new collection with the data from the dump file, technically you will loose all the current data(which is not in dump file) from DB in mongo instance..!!!
-
whoami - fakeFaceTrueSoul about 5 yearsYou should be sure before you use --drop in your command cause it will drop the existing collection in the DB and recreate a new collection with the data from the dump file, technically you will loose all the current data(which is not in dump file) from DB in mongo instance..!!!
-
Marc Maxmeister over 3 yearsit should be
--db
or-d
but not-db