首页 > 解决方案 > 从旧的 mongo 恢复转储

问题描述

我目前正在尝试将使用mongodb:3.4-jessie制作的mongodump恢复到较新的版本mongodb:4.2.3-bionic

当我尝试执行我的命令时: sudo docker exec mongo mongorestore —db=mock —gzip /mongorestore/app

它返回给我这个错误:

2020-05-01T00:01:29.405+0000    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2020-05-01T00:01:29.406+0000    Failed: mongorestore target '/home/user1/mongorestore/app' invalid: stat /home/user1/mongorestore/app: no such file or directory
2020-05-01T00:01:29.406+0000    0 document(s) restored successfully. 0 document(s) failed to restore.

该文件夹app还包含BSON文件json.gz

我无法升级旧的转储,因为它是唯一剩下的东西,并且真的想使用更新版本的 mongo。

非常感谢!

标签: mongodbnosqlmongodumpmongorestore

解决方案


我遇到了同样的问题,但使用 Mongo 5,它的工作原理是这样的:

mongorestore --host=hostname --port=portnum \
    --archive=/path/to/archive.gz --gzip --verbose \
    --nsInclude="mydbname.*" \
    --convertLegacyIndexes

mydbname我在转储集合时使用的数据库的名称在哪里。

如果您现在使用另一个 dbname,那么您需要使用--nsFrom="mydbname.*" --nsTo="newdbname.*"

全部来自:https ://docs.mongodb.com/database-tools/mongorestore/


推荐阅读