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
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
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
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
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!
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.
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