0

I have a database backup and I don't know how to restore it into MongoDB. I'm also not sure exactly what command caused this backup as I changed the OS along with the script that handled this. I believe it was either mongoexport or mongodump.

It shows as a 'data' file:

ubuntu@ubuntu:~/db-backup $ file 2021-05-04 
2021-05-04: data

It has binary ('octet stream') data in this format:

@everyoneposition__v�_id177130053690273793colo#ffffffpermissions��guildId17713005369027379mentionablhoistedname
@everyoneposition__v�_id177131002513145857colo#ffffffpermissions��guildId17713100251314585mentionablhoistedname

How do I restore this data?

0

1 Answer 1

1

The mongoexport tool writes out JSON or CSV files, that snippet is neither, so probably rules that out.

Mongodump can write to a single archive, a directory structure containing BSON and JSON files, or a single BSON file, all with or without gzip.

The file utility should recognize gzip data as such, and an uncompressed mongodump archive might be recognized as either data or an unusual type like DIY-Thermocam raw data.

A BSON file is also recognized by file as data.

To test which this is, execute

bsondump 2021-05-04

If it fails on the first document with invalid BSONSize: showing an enormous or negative value, it is most likely a mongodump archive that you can try to restore with

mongorestore --archive=2021-05-04

If it lists out a series of documents, it is a BSON file that you could restore with

mongorestore --db=databasename --collection=collname 2021-05-04
1
  • Worth to mention that Mongo restore has an option --dryRun you may use. Jul 3, 2021 at 5:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.