How to restore the dump into your running mongodb

╄→гoц情女王★ 提交于 2019-11-27 12:15:11

问题


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.


回答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

1) mongorestore --verbose \path\dump

or

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

Note: Both requires mongod instances.




回答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



回答3:


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.




回答4:


  1. Start mongod
  2. Navigate to folder where you have extracted "enron.zip" in OS shell(cmd in case of windows)
  3. Then type ">mongorestore -d your_db_name dump/enron"



回答5:


You can take a dump to your local machine using this command:

mongodump -h <host>:<port> -u <username> -p <password> -d ubertower-new -o /path/to/destination/directory

You can restore from the local machine to your Mongo DB using this command

mongorestore -h <host>:<port> -u <username> -p <password> -d <DBNAME> /path/to/destination/directory/<DBNAME>



回答6:


For mongoDB database restore use this command here

mongorestore --db databasename --drop dump file path



回答7:


To restore a single database:

1. Backup the 'users' database
$ mongodump --db users

2. Restore the 'users' database to a new database called 'users2'
$ mongorestore --db users2 dump/users



回答8:


I have been through a lot of trouble so I came up with my own solution, I created this script, just set the path inside script and db name and run it, it will do the trick

#!/bin/bash

FILES= #absolute or relative path to dump directory
DB=`db` #db name
for file in $FILES
do

    name=$(basename $file)
    collection="${name%.*}"
    echo `mongoimport --db "$DB" --file "$name" --collection "$collection"`

done



回答9:


mongodump --host test.mongodb.net --port 27017 --db --username --password --authenticationDatabase admin --ssl --out

mongorestore --db --verbose




回答10:


For mongoDB database restore use this command here . First go to your mongodb database location such as For Example : cd Downloads/blank_db/v34000 After that Enter mongorestore -d v34000 ./



来源:https://stackoverflow.com/questions/18931668/how-to-restore-the-dump-into-your-running-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!