Reputation: 890
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.
Upvotes: 42
Views: 56066
Reputation: 56
For anyone who wants to restore the dump of a particular database/cluster to another database/cluster, here's the command:
mongorestore --uri="mongodb+srv://<username>:<password>@<cluster>" dump/
Note: Please execute this command in the dump folder. Otherwise, specify the complete path.
Below is the command to take the dump of the database/cluster.
mongodump --uri="mongodb+srv://<username>:<password>@<cluster>/<databaseName>"
Upvotes: 0
Reputation: 1280
For anyone looking to restore a dump of a different database or MongoDB cluster to a new database or MongoDB cluster, you can do the following in the directory that contains the dump folder, assuming it has the default "dump":
mongorestore --uri "<cluster-connection-string>" /dump
If you're using MongoDB Atlas, you can find your connection string in their UI.
If you don't already have one, you can acquire a dump via this command:
mongodump --uri mongodb+srv://ext_analytics:<PASSWORD>@<DATABASE_CONNECTION_HOST>/<DATABASE>
Upvotes: 0
Reputation: 3704
For anyone else might reach this question after all these years (like I did), and if you are using
dump
directory27017
All you got to do is,
mongorestore dump/
Refer to the mongorestore doc for more info. cheers!
Upvotes: 9
Reputation: 26258
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
.
Upvotes: 73
Reputation: 24309
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
Upvotes: 7
Reputation: 9210
When you do a mongodump
it will dump in a binary format. You need to use mongorestore
to "import" this data.
Mongoimport
is for importing data that was exported using mongoexport
Upvotes: 5