如何使用mongodump转储的数据?

发布于 2024-10-29 14:11:44 字数 196 浏览 11 评论 0原文

我已经使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

行雁书 2024-11-05 14:11:51

为了解决这个问题,我将转储文件夹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;

提笔书几行 2024-11-05 14:11:51

对于 mongo 版本 3 及更高版本,请使用以下命令:

mongorestore --host=localhost --port=27017 --username=root --authenticationDatabase=admin --db=test dump_folder/

Mongo 之后将询问密码

For mongo version 3 and above use the command below:

mongorestore --host=localhost --port=27017 --username=root --authenticationDatabase=admin --db=test dump_folder/

Mongo will ask password after that

若言繁花未落 2024-11-05 14:11:50

如先前的答案中所述,您必须使用 mongorestore 而不是 mongoimport 。添加到先前的答案之后,当您的mongoDB运行时,执行以下命令以从转储目录还原您的转储,

mongorestore dump

这将导入所有集合中的所有集合中的 myDB 数据库。但是,这不会在还原之前删除数据库。如果您希望在导入之前删除数据库,

mongorestore --drop dump

则将在 myDB 目录中的BSON文件作为 myDB 数据库中的集合而恢复。有关 mongorestore 的更多信息,请查看此处的文档。

As mentioned in the previous answers, you have to use mongorestore instead of mongoimport. Adding to the previous answers, when your mongodb is running, execute the following command to restore your dump from the dump directory,

mongorestore dump

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,

mongorestore --drop dump

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.

贩梦商人 2024-11-05 14:11:50

使用 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)

淡淡離愁欲言轉身 2024-11-05 14:11:49

我正在使用 mongodumpmongorestore 用于日常备份和从备份恢复。我有两个 .bat 文件:
首先,对于备份,您只需指定主机数据库名称和备份文件夹:

SET host=localhost:27020
SET dbNameToDump=MyDB
SET backupsFolder=Backups

mongodump.exe --host %host% --db %dbNameToDump%

SET date="%date:~10,4%-%date:~4,2%-%date:~7,2%.%time:~0,2%-%time:~3,2%"
cd %backupsFolder%
md %date%

xcopy /e ..\dump %date%

rmdir /s /q ..\dump

在上面的bat文件中创建名称如下的文件夹 2011-03-31.11-17(yyyy-MM-dd.hh-ss) 在包含来自指定数据库的转储集合的备份文件夹中。在文件资源管理器中,它看起来像这样:

在此处输入图像描述

我用于恢复指定转储文件的第二个bat文件(在这里您也可以需要指定数据库名称和包含转储文件的文件夹):

SET host=localhost:27020
SET dbNameToRestore=MyDB
SET restoreFolder=Restore

mongorestore.exe --host %host% --db %dbNameToRestore% %restoreFolder%

在文件资源管理器中:

在此处输入图像描述

另外,我正在使用 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:

SET host=localhost:27020
SET dbNameToDump=MyDB
SET backupsFolder=Backups

mongodump.exe --host %host% --db %dbNameToDump%

SET date="%date:~10,4%-%date:~4,2%-%date:~7,2%.%time:~0,2%-%time:~3,2%"
cd %backupsFolder%
md %date%

xcopy /e ..\dump %date%

rmdir /s /q ..\dump

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:

enter image description here

Second bat file i use for retore specified dumped files(here you also need specify database name and folder with dumped files):

SET host=localhost:27020
SET dbNameToRestore=MyDB
SET restoreFolder=Restore

mongorestore.exe --host %host% --db %dbNameToRestore% %restoreFolder%

In files explorer:

enter image description here

In additional, i am using windows schedule to automate backup process.

Hope above information will be useful for someone.

ˉ厌 2024-11-05 14:11:48

您需要使用 mongorestore,而不是 mongoimport ...,它用于导入 json 或 csv 等。

来自 back-up-with-mongodump 文档:

mongodump 从 MongoDB 数据库读取数据并创建高保真 BSON 文件,mongorestore 工具可使用该文件填充 MongoDB 数据库。

mongodumpmongorestore 是简单而高效的备份工具
启动和恢复小型 MongoDB 部署,但并不理想
捕获较大系统的备份。

您可以在下面的文档中阅读有关 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:

mongodump reads data from a MongoDB database and creates high fidelity BSON files which the mongorestore tool can use to populate a MongoDB database.

mongodump and mongorestore are simple and efficient tools for backing
up and restoring small MongoDB deployments, but are not ideal for
capturing backups of larger systems.

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文