Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import dumped Mongodb?

Dumped a MongoDB successfully:

$ mongodump -h ourhost.com:portnumber -d db_name01 -u username -p 

I need to import or export it to a testserver and have struggle with it, please help me figure out.

I tried some ways:

$ mongoimport -h host.com:port -c dbname -d dbname_test -u username -p connected to host. Password: ... 

Gives this error:

assertion: 9997 auth failed: { errmsg: "auth fails", ok: 0.0 }  $ mongoimport -h host.com:port -d dbname_test -u username -p 

Gives this error:

no collection specified! 

How to specify which collection to use? What should I use for -d? What I'd like to upload or what I want to use as test out there? I would like to import the full DB not only collection of it.

like image 732
YogiZoli Avatar asked Nov 09 '11 19:11

YogiZoli


People also ask

How do I import a database into MongoDB?

To import data to a MongoDB database, you can use mongoimport to import specific collections data, or you can use mongorestore to import a binary (BSON) full database backup. The exported database file must be stored locally on the same machine as your client.

How do I restore a dropped database in MongoDB?

The most reliable way to recover deleted data is to use a Supported Backup Method with continuous backup (for example, agent-based backup like MongoDB Ops Manager) or an acceptable schedule for your recovery scenarios. Ops Manager also includes a Queryable backup feature to help with selective recovery of data.

Where is MongoDB dump folder?

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.


2 Answers

The counterpart to mongodump is mongorestore (and the counterpart to mongoimport is mongoexport) -- the major difference is in the format of the files created and understood by the tools (dump and restore read and write BSON files; export and import deal with text file formats: JSON, CSV, TSV.

If you've already run mongodump, you should have a directory named dump, with a subdirectory for each database that was dumped, and a file in those directories for each collection. You can then restore this with a command like:

mongorestore -h host.com:port -d dbname_test -u username -p password dump/dbname/ 

Assuming that you want to put the contents of the database dbname into a new database called dbname_test.

like image 109
dcrosta Avatar answered Sep 30 '22 10:09

dcrosta


You may have to specify the authentication database

mongoimport -h localhost:27017 --authenticationDatabase admin -u user -p -d database -c collection --type csv --headerline --file awesomedata.csv  
like image 45
Ricky Sahu Avatar answered Sep 30 '22 09:09

Ricky Sahu