问题描述
我正在尝试使用 mongodump
后跟 mongorestore
将一些数据从一个 mongo 数据库复制到另一个数据库。
mongodump
成功:
> mongodump "<connection_string>/testDB1?ssl=true&authSource=admin&readPreference=secondaryPreferred" -c testCollection --archive=test_dump --ssl
...
2021-04-16T19:45:21.801-0600 [#######################.] testDB1.testCollection 43866235/43987468 (99.7%)
2021-04-16T19:45:24.800-0600 [#######################.] testDB1.testCollection 43896379/43987468 (99.8%)
2021-04-16T19:45:27.802-0600 [#######################.] testDB1.testCollection 43956660/43987468 (99.9%)
2021-04-16T19:45:30.430-0600 [########################] testDB1.testCollection 43992193/43987468 (100.0%)
2021-04-16T19:45:30.436-0600 done dumping testDB.testCollection (43992193 documents)
但是,mongorestore
返回时没有错误消息但没有恢复任何数据:
> mongorestore "<connection_string>/testDB2?retryWrites=true&w=majority" --archive=test_dump --ssl --drop --nsFrom testDB1.testCollection --nsTo testDB2.testCollection
2021-04-16T20:59:46.129-0600 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead,i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2021-04-16T20:59:46.146-0600 preparing collections to restore from
2021-04-16T21:01:03.277-0600 0 document(s) restored successfully. 0 document(s) Failed to restore.
关于我可能做错了什么的任何想法?我正在使用 mongodb-community
版本 4.4
:
> mongod --version
db version v4.4.4
Build Info: {
"version": "4.4.4","gitVersion": "8db30a63db1a9d84bdcad0c83369623f708e0397","modules": [],"allocator": "system","environment": {
"distarch": "x86_64","target_arch": "x86_64"
}
}
解决方法
从连接字符串中删除“testDB2”数据库规范。它与 --nsXXX 参数冲突:
mongorestore "<connection_string>/?retryWrites=true&w=majority" \
--archive=test_dump --ssl --drop --nsFrom testDB1.testCollection \
--nsTo testDB2.testCollection