我正试图使用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