Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongorestore of a db causing me trouble

Tags:

mongodb

I'm new to MongoDB and I have hard time to backup my local DB and restore it on my server. I found the link on Mongo's website : http://www.mongodb.org/display/DOCS/Import+Export+Tools but I still have problems with the restore.

When I do my backup I call

mongodump --db Gen 

Then I see that all the collections are dump in /bin/dump/Gen folder

I copy-paste from local to the server in the same folder the call

mongorestore --db Gen --drop --dbpath dump/Gen 

But I get the following : Error : root directory must be a dump of a single database when specifying a db name with --db

like image 387
VinnyG Avatar asked Oct 07 '10 17:10

VinnyG


People also ask

Does Mongorestore overwrite data?

No. From mongorestore: If you restore to an existing database, mongorestore will only insert into the existing database, and does not perform updates of any kind. If existing documents have the same value _id field in the target database and collection, mongorestore will not overwrite those documents.

What is Mongorestore?

mongorestore is a simple utility that is used to restore backups. It can load data from either: A database dump file created by the mongodump command. The standard input to a mongod or mongos instance.


2 Answers

Ok I find out what I'm doing wrong :

I was doing

mongorestore --db Gen --drop --dbpath dump/Gen 

But without the --dbpath it works just fine!

mongorestore --db Gen --drop dump/Gen 

Thanks everyone!

like image 121
VinnyG Avatar answered Oct 06 '22 03:10

VinnyG


I think your folder structure may be getting messed up when you try to move it. For instance, this works for me:

$ ./mongodump --db Gen $ ./mongorestore --db Gen --drop dump/Gen/ 

Can you try not moving the dump directory, and restoring from /bin/dump/Gen?

The directory you specify should have .bson files in it, e.g.,

$ ls /bin/dump/Gen foo.bson  bar.bson  baz.bson 
like image 43
kristina Avatar answered Oct 06 '22 05:10

kristina