Search code examples
mongodbmongodumpmongorestore

mongorestore returns "0 document(s) restored successfully. 0 document(s) failed to restore."


I'm trying to copy some data from one mongo database to another using mongodump followed by mongorestore.

mongodump succeeds:

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

However, mongorestore returns without an error message but without restoring any data:

> 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.

Any ideas on what I could be doing wrong? I'm using mongodb-community version 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"
    }
}

Solution

  • Remove "testDB2" database specification from the connection string. It conflicts with --nsXXX parameters:

    mongorestore "<connection_string>/?retryWrites=true&w=majority" \
    --archive=test_dump --ssl --drop --nsFrom testDB1.testCollection \
    --nsTo testDB2.testCollection