如何使用mongodump转储的数据?
我已经使用 mongodump
转储我的 mongodb 数据库,它在 dump/mydb
下创建了一些 bson 文件,
但我不知道如何使用它们。我尝试了 mongoimport
,但似乎无法导入 bson 数据。那么如何使用这些bson文件呢?如何将它们导入到另一个mongodb?
I have used mongodump
to dump my database of mongodb, it created some bson files under dump/mydb
But I don't know how to use them. I tried mongoimport
, but seems it can't import bson data. Then how to use these bson files? How to import them to another mongodb?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
为了解决这个问题,我将转储文件夹dbdump(其中包含bson文件)复制到mongodb的bin目录中,并在命令提示符中执行以下命令:
1.
cd“MongoDB bin 文件夹的路径”
(示例:cd C:\Program Files\MongoDB\Server\3.2\bin)
2.
mongorestore.exe --dir ./目录名称 --db 数据库名称
(示例:mongorestore --dir ./dbdump --db testdb)
转储文件夹中的所有 bson 文件都将导入到数据库中。
您可以通过执行以下命令来验证这一点:
cd“MongoDB bin 文件夹的路径”
蒙戈.exe
显示数据库;
For resolving this, I copied the dump folder,dbdump(which contains bson files) to bin directory of mongodb and executed the below commands in command prompt:
1.
cd "path to MongoDB's bin folder"
(Example: cd C:\Program Files\MongoDB\Server\3.2\bin)
2.
mongorestore.exe --dir ./directory name --db database-name
(Example: mongorestore --dir ./dbdump --db testdb)
All bson files in the dump folder will be imported into your database.
You can verfiy this by executing the below commands :
cd "path to MongoDB's bin folder"
mongo.exe
show dbs;
对于 mongo 版本 3 及更高版本,请使用以下命令:
Mongo 之后将询问密码
For mongo version 3 and above use the command below:
Mongo will ask password after that
如先前的答案中所述,您必须使用
mongorestore
而不是mongoimport
。添加到先前的答案之后,当您的mongoDB运行时,执行以下命令以从转储目录还原您的转储,这将导入所有集合中的所有集合中的 myDB 数据库。但是,这不会在还原之前删除数据库。如果您希望在导入之前删除数据库,
则将在 myDB 目录中的BSON文件作为 myDB 数据库中的集合而恢复。有关 mongorestore 的更多信息,请查看此处的文档。
As mentioned in the previous answers, you have to use
mongorestore
instead ofmongoimport
. Adding to the previous answers, when your mongodb is running, execute the following command to restore your dump from the dump directory,This will import all the collections into your mydb database. However this doesn't drop the database before restoring. If you wish to drop the database before importing,
The bson files in the mydb directory will be restored as the collections inside mydb database. For more info on mongorestore check the documentation here.
使用 mongorestore。 mongoimport 适用于 mongoexport 的输出。 mongodump & mongorestore 处理二进制数据文件,而导入/导出处理 json、csv 等(人类可读格式)
Use mongorestore. mongoimport works on the output of mongoexport. mongodump & mongorestore work on binary data files while import / export work on json, csv, etc.. (human readable formats)
我正在使用 mongodump,mongorestore 用于日常备份和从备份恢复。我有两个
.bat
文件:首先,对于备份,您只需指定主机数据库名称和备份文件夹:
在上面的bat文件中创建名称如下的文件夹
2011-03-31.11-17(yyyy-MM-dd.hh-ss)
在包含来自指定数据库的转储集合的备份文件夹中。在文件资源管理器中,它看起来像这样:我用于恢复指定转储文件的第二个bat文件(在这里您也可以需要指定数据库名称和包含转储文件的文件夹):
在文件资源管理器中:
另外,我正在使用 Windows安排自动化备份过程。
希望以上信息对某人有用。
I am using mongodump, mongorestore for daily backups and restoring from backup. I have two
.bat
files:First, for backup, where you need just specify host database name and backup folder:
Above bat file create folder with name like this
2011-03-31.11-17(yyyy-MM-dd.hh-ss)
in folder Backups with dumped collections from specified database. In files explorer it looks like so:Second bat file i use for retore specified dumped files(here you also need specify database name and folder with dumped files):
In files explorer:
In additional, i am using windows schedule to automate backup process.
Hope above information will be useful for someone.
您需要使用 mongorestore,而不是 mongoimport ...,它用于导入 json 或 csv 等。
来自
back-up-with-mongodump
文档:您可以在下面的文档中阅读有关 mongorestore 的更多信息;我会看一下并阅读它们,因为它们非常有帮助。
http://www.mongodb.org/display/DOCS/Import +Export+Tools#ImportExportTools-mongorestore
您还可以查看 http://learnmongo.com 了解提示和信息帮助!
You need to use mongorestore, not mongoimport ... which is used for things like importing json, or csv, etc.
From the
back-up-with-mongodump
docs:You can read more about mongorestore in the docs below; I'd take a look and read up on them as they are very helpful.
http://www.mongodb.org/display/DOCS/Import+Export+Tools#ImportExportTools-mongorestore
You can also check out http://learnmongo.com for tips and help!