Mongorestore --gzip --archive failed w/ - 0 document(s) restored successfully. 0 document(s) failed

after many hours scouring the internet (including on Stackoverflow), checking the documentation back and forth of the official MongoDB website. I still did not find the solution why my archived file with mongodump is not restored with the following commands

mongorestore --gzip --drop --nsInclude="*" --archive=/./././code/backups/notura-db-1659281356578.gzip -v

I get the following output:

2022-07-31T23:55:19.574+0200    using write concern: &{majority false 0}
2022-07-31T23:55:19.606+0200    will listen for SIGTERM, SIGINT, and SIGKILL
2022-07-31T23:55:19.607+0200    connected to node type: standalone
2022-07-31T23:55:19.619+0200    archive format version "0.1"
2022-07-31T23:55:19.619+0200    archive server version "5.0.3"
2022-07-31T23:55:19.619+0200    archive tool version "100.5.1"
2022-07-31T23:55:19.620+0200    preparing collections to restore from
2022-07-31T23:55:19.632+0200    demux finishing (err:<nil>)
2022-07-31T23:55:19.632+0200    received  from namespaceChan
2022-07-31T23:55:19.632+0200    restoring up to 4 collections in parallel
2022-07-31T23:55:19.632+0200    building indexes up to 4 collections in parallel
2022-07-31T23:55:19.632+0200    0 document(s) restored successfully. 0 document(s) failed to restore.

I do not get any error message, nor does my database getting updated.

I am running MongoDB 5.0.3 Community

Any help is highly appreciated!

Aron

How was the dump created?
What command was used?

I used the following command to dump the library:

mongodump --archive=/./././backups/notura-db-1659281356578.gzip --db=notura-db --gzip

Is your mongodump and mongorestore of same version?
Is your source DB version and target DB version same?
Did you try without gzip option?
I tested it on my Windows mongodb version 4.0.5.Works fine with both archive and gzip
Note:I am not using mongodb tools.In old versions the utility tools used to come with mongodb installation

Thanks for your help. I have altered a few things to be sure, based on the feedback you have given me.

I changed the the dump to:
mongodump --uri="mongodb://localhost:27017" --db="notura-recipies" --out=/./././code/backups/

This works, it dumps the folder with the files in it (2 .bson and 2 .json files), then I altered the restore to the following mongorestore instruction:

mongorestore --drop /./././code/backups/notura-recipies -v

The verbose output is a bit different though, but still the same end result:

2022-08-01T20:09:35.949+0200    using write concern: &{majority false 0}
2022-08-01T20:09:35.969+0200    will listen for SIGTERM, SIGINT, and SIGKILL
2022-08-01T20:09:35.970+0200    connected to node type: standalone
2022-08-01T20:09:35.971+0200    mongorestore target is a directory, not a file
2022-08-01T20:09:35.971+0200    preparing collections to restore from
2022-08-01T20:09:35.971+0200    don't know what to do with file "/./././code/backups/notura-recipies/recipes.bson", skipping...
2022-08-01T20:09:35.971+0200    don't know what to do with file "/./././code/backups/notura-recipies/recipes.metadata.json", skipping...
2022-08-01T20:09:35.971+0200    don't know what to do with file "/./././code/backups/notura-recipies/users.bson", skipping...
2022-08-01T20:09:35.971+0200    don't know what to do with file "/./././code/backups/notura-recipies/users.metadata.json", skipping...
2022-08-01T20:09:35.971+0200    restoring up to 4 collections in parallel
2022-08-01T20:09:35.971+0200    building indexes up to 4 collections in parallel
2022-08-01T20:09:35.971+0200    0 document(s) restored successfully. 0 document(s) failed to restore.

It seems like that the mongorestore is somehow unable to read in the files - sigh -

Please share the content of the 2 .json files.

Please redo the mongodump with --verbose and share the output.

Note that you are doing something very risky. You do mongorestore --drop into the same database of the same server for which you did mongodump. I think you might lose your data if something goes wrong. You might want to use --dryrun until you are certain of what you are doing.

If the collections are not too big, try mongoexport with --verbose and share the output.

Why do you start your path with

In the examples I saw, the path specified in mongorestore must match the path specified in mongodump. You seem to add the /notura-recipies in mongorestore compared to mongodump, so you might start mongorestore one directory too deep.

Since you mongodump and mongorestore into the same server, you might want to use --nsFrom and --nsTo to restore into a different database.

Thanks, these are good questions! the two .json files consist of the following information:

Recipes metadata:
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"title":{"$numberInt":"1"}},"name":"title_1","background":true,"unique":true},{"v":{"$numberInt":"2"},"key":{"slug":{"$numberInt":"1"}},"name":"slug_1","background":true,"unique":true}],"uuid":"45ee68c614634f2c8b3d7c3abe5343c2","collectionName":"recipes","type":"collection"}

Users metadata:
{"indexes":[{"v":{"$numberInt":"2"},"key":{"_id":{"$numberInt":"1"}},"name":"_id_"},{"v":{"$numberInt":"2"},"key":{"email":{"$numberInt":"1"}},"name":"email_1","background":true,"unique":true}],"uuid":"ee929337aa1b4da1a2f447775d11726b","collectionName":"users","type":"collection"}

Nope, it is a small collection. I used mongoexport:
mongoexport --uri="mongodb://localhost:27017" --collection="recipes" --db="notura-recipies" --out /Users/aron/Desktop/code/backups/recipes.json -v

I have two collections, I exported one here. The other one would be pretty much the same.

Output is:

2022-08-02T09:05:24.414+0200   will listen for SIGTERM, SIGINT, and SIGKILL
2022-08-02T09:05:24.430+0200    connected to: mongodb://localhost:27017
2022-08-02T09:05:24.437+0200    exported 6 records

I started with /././. to remove the actual path, since that is not important to know and improve readability. On the actual server, this is shorter anyway. So I thought. Sorry if this confused you.

The reason why I went one layer deeper is that in backups there will be multiple backups, with nodeJS I select the latest one and will feed that to my database in case of an accident. The other ones I can download with something like FileZilla.

But you re right about this, after removing notura-recipies the files got restored! :slight_smile:

You mean that I should rename the database from one to. new one, with:

    --nsFrom "dbname.*" 
    --nsTo "new_dbname.*" 

My idea was to pluck the latest archived backup in the folder and restore that, without any duplications. Especially when these files get larger.

How can I best do this? I clearly did not do it right - sigh -

Thanks for your help guys, this helps me tremendously!

2 Likes

That is what I meant but for your use case (restoring from backups) you do not need that as you really want to overwrite what is there.

To handle the following:

You need to use https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--nsInclude

1 Like

Thank you! :slight_smile: With the information you have given me, I will be able to correct the issue. Which is making sure that it is being dumped correctly before it can be restored correctly!