skip to Main Content

A few months ago I did a dump of my mongodump db and it resulted in a single file instead of multiple bson and json files:

![enter image description here

I tried to restore it using:

mongorestore –drop –db lodeep dump

dump is the folder containing the file but I get this:

enter image description here

I don’t remember how exactly I made this dump. And why it’s not like the usual dump. And why the file has no extension. I’m a bit lost. I really need this data.

When I do this:

head mongodump-prod-db

I see that it’s indeed my database and its collections:
enter image description here

Any help please?


I remembered now I used this command to dump it:

mongodump –uri
‘mongodb+srv://XXXX:[email protected]/DB_NAME’
–archive="mongodump-prod-db" –forceTableScan

And if I want to restore it to the cloud, I do this:

mongorestore –uri
‘mongodb+srv://XXXX:[email protected]/DB_NAME’
–archive="mongodump-prod-db" –nsFrom=’DB_NAME.‘ –nsTo=’copy_new_db.

I tried to restore it locally:

mongorestore –uri ‘mongodb://localhost:27017/<local_dbname>’
–archive="mongodump-prod-db"

But it results in this:
enter image description here


I also tried to restore it to the cloud:

mongorestore –uri
‘mongodb+srv://XXXXXX:[email protected]/myDatabase’
–archive="mongodump-prod-db" –nsFrom=’myDatabase.originalCollection’ –nsTo=’myDatabase.copy_new_collection’

And I see this:
enter image description here


I tried this:

mongorestore –archive="mongodump-prod-db" –db restoreddb –verbose

It shows it’s reading collections names but then it restores nothing:

2024-10-06T16:05:45.499+0200    using write concern: &{majority <nil> 0s}
2024-10-06T16:05:45.524+0200    The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2024-10-06T16:05:45.551+0200    archive prelude <dbname>.users
2024-10-06T16:05:45.560+0200    archive prelude <dbname>.badges
2024-10-06T16:05:45.631+0200    preparing collections to restore from
2024-10-06T16:06:16.228+0200    0 document(s) restored successfully. 0 document(s) failed to restore.

2

Answers


  1. Chosen as BEST ANSWER

    Okay this is a bit stupid. But the database name of the dump is literally < dbname > (minus the spaces) so when I run this command:

    mongorestore --archive="mongodump-prod-db" --verbose --nsInclude=.*

    mongorestore ignore <> and interprets it as dbname. And so it doesn't find the database in the dump.

    So I had to do this:

    mongorestore --archive="mongodump-prod-db" --verbose 
    --nsFrom="<dbname>.*" --nsTo="newdbname.*"
    

    And it worked!


  2. You can restore a single file dump with the command

    mongorestore --drop < dump.gz
    

    The database name will be taken from the file. If you used the --archive flag when doing the dump, you have to add the option to the restore command.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search