Reputation: 6911
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
Upvotes: 37
Views: 41502
Reputation: 11
It must be any other directory in a dump directory. So, remove the directory first and re-run the command mongorestore -d db dump/db
Upvotes: 1
Reputation: 12224
This is what ended up working for me (mydb
is the name of my database):
mongorestore --drop -db mydb mydbbackup/mydb/
After my mongodump
:
mongodump -d mydb -o mydbbackup
Upvotes: 4
Reputation: 39
Example:
./mongorestore -d db -c mycollection dump/db
will raise the following error
ERROR: ERROR: root directory must be a dump of a single collection
ERROR: when specifying a collection name with --collection
you can remove the -c option to rolve this error.Beacuse dump/db specify the db, but not collection.
Upvotes: -1
Reputation: 3804
An additional note for whoever doesn't want to be annoyed by the error "root directory must be a dump of a single database when specifying a db name with --db"
When specifying --db and without --collection (restoring a whole database): - the given path must be a directory path - the directory must not contain any other files than .bson or .json. It took me a while to realize that the hidden .svn folder (if you use SVN) will mess up the script
Upvotes: 3
Reputation: 6911
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!
Upvotes: 46
Reputation: 23591
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
Upvotes: 5