mongodb 一个数据库的 Mongorestore 给我带来了麻烦
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3884418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mongorestore of a db causing me trouble
提问by VinnyG
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+Toolsbut I still have problems with the restore.
我是 MongoDB 的新手,我很难备份我的本地数据库并在我的服务器上恢复它。我在 Mongo 的网站上找到了链接:http: //www.mongodb.org/display/DOCS/Import+Export+Tools但我仍然遇到恢复问题。
When I do my backup I call
当我做备份时,我打电话
mongodump --db Gen
Then I see that all the collections are dump in /bin/dump/Gen
folder
然后我看到所有的集合都在/bin/dump/Gen
文件夹中转储
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
但我得到以下信息:
Error : root directory must be a dump of a single database when specifying a db name with --db
回答by VinnyG
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!
但是没有 --dbpath 它工作得很好!
mongorestore --db Gen --drop dump/Gen
Thanks everyone!
谢谢大家!
回答by kristina
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?
您可以尝试不移动转储目录,并从 /bin/dump/Gen 恢复吗?
The directory you specify should have .bson files in it, e.g.,
您指定的目录中应该有 .bson 文件,例如,
$ ls /bin/dump/Gen
foo.bson bar.bson baz.bson
回答by Stunner
This is what ended up working for me (mydb
is the name of my database):
这就是最终对我有用的东西(mydb
是我的数据库的名称):
mongorestore --drop -db mydb mydbbackup/mydb/
After my mongodump
:
在我之后mongodump
:
mongodump -d mydb -o mydbbackup
回答by Thanh Trung
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"
对于不想被错误“使用--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
当指定 --db 且不使用 --collection 时(恢复整个数据库): - 给定的路径必须是目录路径 - 目录不得包含除 .bson 或 .json 之外的任何其他文件。我花了一段时间才意识到隐藏的 .svn 文件夹(如果您使用 SVN)会弄乱脚本
回答by mamadtama
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
它必须是转储目录中的任何其他目录。因此,首先删除目录并重新运行命令mongorestore -d db dump/db
回答by JunZhang
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.
您可以删除 -c 选项来解决此错误。因为 dump/db 指定了 db,而不是集合。