Mongorestore of a db causing me trouble

前端 未结 6 832
猫巷女王i
猫巷女王i 2020-12-29 19:26

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

相关标签:
6条回答
  • 2020-12-29 19:34

    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
    
    0 讨论(0)
  • 2020-12-29 19:35

    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
    
    0 讨论(0)
  • 2020-12-29 19:38

    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

    0 讨论(0)
  • 2020-12-29 19:50

    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!

    0 讨论(0)
  • 2020-12-29 19:54

    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.

    0 讨论(0)
  • 2020-12-29 19:58

    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

    0 讨论(0)
提交回复
热议问题