Feng Yu
Feng Yu

Reputation: 1493

Mongorestore don't know what to do with file "db/collection.bson", skipping

I want to migrate my mongodb from 2.0 to 3.0. So I followed the official doc to use mongodump to backup my dbs and use mongorestore to restore the dbs to mongodb 3.0.

But when I use mongorestore, it tells me "don't know what to do with file "db/collection.bson", skipping...".

Nothing to do. How could I migrate my dbs?

Thanks.

EDIT: Here is my steps.

Use mongodump in mongodb 2.0

mongodump
tree dump
    db
    ├── collection-1.bson
    ├── collection-2.bson
    ├── collection-3.bson
    ├── ...

Copy db directory to mongodb 3.0 server.

On the mongodb 3.0 server calls mongorestore db

But I get this error:

mongorestore db
2015-03-10T09:36:26.237+0800    building a list of dbs and collections   to restore from db dir
2015-03-10T09:36:26.237+0800    don't know what to do with file "db/collection-1.bson", skipping...
2015-03-10T09:36:26.237+0800    don't know what to do with file "db/collection-2.bson", skipping...
2015-03-10T09:36:26.237+0800    don't know what to do with file "db/collection-3.bson", skipping...
...
2015-03-10T09:36:26.237+0800    done

Upvotes: 62

Views: 68534

Answers (11)

Nemeton
Nemeton

Reputation: 743

I used docker to start my mongo db instance & I had default username and password auth set for database. Below is how my restore looked like.

mongorestore --authenticationDatabase admin -u root -p example -d test-db /data/test-db

So in-short something of this sort should work.

mongorestore --authenticationDatabase admin -u {USERNAME} -p {PASSWORD} -d {DB_NAME} {/DUMP_PATH}

Upvotes: 0

roni naruka
roni naruka

Reputation: 79

mongorestore --uri "mongodb+srv://<user>:<password>@<host>" -d <dbname>  <dump dir. address ./something/like/this>

This work fine for me

Upvotes: 0

Sachin Vairagi
Sachin Vairagi

Reputation: 5344

Following command worked for me in mongoDB 6.0 -

mongorestore --host localhost --port 27017 --db DB-NAME DB-BACKUP-PATH

Please replace DB-NAME and DB-BACKUP-PATH with your actual values. For ex.

mongorestore --host localhost --port 27017 --db demo_db /home/ubuntu/db-backup

Where "/home/ubuntu/db-backup" contains all collections in bson and json format.

Upvotes: 4

Muhammad Asad
Muhammad Asad

Reputation: 55

Not directly related to your situation but someone could stumble upon this post with similar error for this reason

In my case, the data was provided to me and had been dumped using

mongodump --db ${DB_NAME} --gzip -o ${BACKUP_FILE_GZ}

To restore, you must use following format:

mongorestore --gzip --db "${DB_NAME_RESTORE}" ${BACKUP_FILE_GZ}/${DB_NAME}

Upvotes: 1

Shashwat Gupta
Shashwat Gupta

Reputation: 5272

You want to run mongorestore on the dump directory, not the db/ directory.

mongorestore  dump/

Upvotes: 0

Amit Kr.
Amit Kr.

Reputation: 69

If you have lost your mongoDb just try running this command:

mongorestore -d destination-db --gzip source-db

Where:

  • destination-db is the name of the destination database
  • source-db is the name of the source database.

Upvotes: 6

Aviv
Aviv

Reputation: 14527

In order to import data to your mongodb ,You need to specify --db configuration in mongorestore function with name and path, this works for me for bson and json files as well:

mongorestore --db <dbName> <dbPath>

check the data was imported properly using mongo cli

mongo
show databases
use <dbName>
show collections

Upvotes: 5

Ankit Kumar Rajpoot
Ankit Kumar Rajpoot

Reputation: 5600

Try this one.

mongorestore -db dataBaseName dataBasePath

Upvotes: 2

Artem Dolobanko
Artem Dolobanko

Reputation: 2349

This answer isn't directly related to your issue case, but the same error output you will receive trying to restore mongo data, dumped with --archive option, available since MongoDB 3.2 version. To resolve this you need to specify --gzip parameter in your mongorestore command. Example:

mongorestore -d destination_db --gzip /path/to/source/db

Upvotes: 42

Matthew Beck
Matthew Beck

Reputation: 596

With mongorestore, the path of those dump files is a required parameter; you've got that right so far, by indicating db.

It is also a good idea as Peter has said to indicate a database to restore the dump files into collections with a /d switch.

Something I didn't realize while struggling with this is that a mongod must be running to consume the restoration. If you have more than 1 mongod running, you should definitely indicate a port with the --port switch. The code that worked for me was:

mongod --dbpath config --port 27019 --logpath log.config --logappend

And in another CLI:

mongorestore --port 27019 /d config config

followed by

mongo localhost:27019/config

to verify that the collections were filled properly.

Upvotes: 0

Peter
Peter

Reputation: 1661

It seems one must also specify -d in 3.0 like this:

mongorestore -d db db

Upvotes: 152

Related Questions