Reputation: 757
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:
I tried to restore it using:
mongorestore --drop --db lodeep dump
dump is the folder containing the file but I get this:
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:
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"
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'
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.
Upvotes: 1
Views: 76
Reputation: 2050
You can restore a single file dump with the command
mongorestore --drop < dump
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.
Upvotes: -1
Reputation: 757
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!
Upvotes: 0