Search code examples
mongodbmongodumpmongorestore

Mongo Restore don't know what to do with file error


I am restoring a Mongo database and i am getting the following error

2021-07-25T14:53:21.972+0000    preparing collections to restore from
2021-07-25T14:53:21.977+0000    don't know what to do with file "/mongoBackUp/manudatabase/customer.bson", skipping...
2021-07-25T14:53:21.978+0000    don't know what to do with file "/mongoBackUp/manudatabase/customer.metadata.json", skipping...
2021-07-25T14:53:21.979+0000    don't know what to do with file "/mongoBackUp/manudatabase/product.bson", skipping...
2021-07-25T14:53:21.979+0000    don't know what to do with file "/mongoBackUp/manudatabase/product.metadata.json", skipping...
2021-07-25T14:53:21.980+0000    don't know what to do with file "/mongoBackUp/manudatabase/productCategory.bson", skipping...
2021-07-25T14:53:21.980+0000    don't know what to do with file "/mongoBackUp/manudatabase/productCategory.metadata.json", skipping...
2021-07-25T14:53:21.981+0000    don't know what to do with file "/mongoBackUp/manudatabase/sale.bson", skipping...
2021-07-25T14:53:21.982+0000    don't know what to do with file "/mongoBackUp/manudatabase/sale.metadata.json", skipping...
2021-07-25T14:53:21.982+0000    don't know what to do with file "/mongoBackUp/manudatabase/student.bson", skipping...
2021-07-25T14:53:21.983+0000    don't know what to do with file "/mongoBackUp/manudatabase/student.metadata.json", skipping...
2021-07-25T14:53:21.983+0000    0 document(s) restored successfully. 0 document(s) failed to restore.

Below is the command that i am using to restore


mongorestore --nsInclude=manudatabase.* --authenticationDatabase admin --username r*****q --password r*****q /mongoBackUp/manudatabase

I have tried using below command and it works just fine but its deprecated

mongorestore --db manudatabase --username r*****q --password r*****q --authenticationDatabase admin /mongoBackUp/manudatabase

Below is the depreciation error


The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}

So i decided to replace -db manudatabase with --nsInclude=manudatabase.* and thats where the problems with don't know what to do with file started


Solution

  • Through my own research in questions such as the one asked in stack overflow question below i have found the answer

    The question was asked in stack overflow below link Stack Overflow Question Answered on Don't know what to do with file “/”, skipping

    The Solution is mongorestore expects the dump folder to contain sub-folders with the database name, which in turn contain the BSON dump and the metadata. The error you're seeing is because it didn't find any subdirectory with BSON/metadata files in it.

    So my command should have been like this below

    
    mongorestore --nsInclude=manudatabase.* --authenticationDatabase admin --username r*****q --password r*****q /mongoBackUp
    
    

    instead of

    
    mongorestore --nsInclude=manudatabase.* --authenticationDatabase admin --username r*****q --password r*****q /mongoBackUp/manudatabase
    
    

    I Changed

    /mongoBackUp/manudatabase
    
    
    

    To

    
    /mongoBackUp/
    
    

    And it now restores the database perfectly