6

I have created a dump in an archive file by the following command :

mongodump --archive=newcollection.1.archive --db neel --collection newcollection

While restoring with the mongorestore i am getting an error :the --db and --collection args should only be used when restoring from a BSON file.

I got the syntax from [https://docs.mongodb.com/manual/reference/program/mongorestore/#examples][1] .

I fired the following command :

mongorestore --archive=newcollection.1.archive  --db backup2.
Neel
  • 71
  • 1
  • 1
  • 5

3 Answers3

8

use --nsFrom and --nsTo

see example :

mongodump -h foo.com:27017 --db source_db_name --gzip --archive | mongorestore --drop -vvvvvv -h bar.com:27017 --nsFrom source_db_name.collection_name --nsTo destination_db_name.* --gzip --archive

the format for nsFrom and nsTo is database_name.collection_name, and you can use wildcards ( like i did for destination_db_name.* ) for the same

more info

Edwin O.
  • 4,998
  • 41
  • 44
  • The example from the docs was giving me the `E11000 duplicate key error collection: db.collection index: _id_ dup key` error. Your answer gave me the hint to remove quotes from `--nsFrom` and `--nsTo`, and the error went away. – KalenGi Jul 13 '20 at 10:29
1
mongorestore  --archive=<filename>.archive
A J
  • 191
  • 3
  • 4
0

when you want to restore a mongodb archived database go to file path and write

mongorestore --archive=filename.archive

and then press enter it will restore all data of from archive file to your local database.

Ahad
  • 49
  • 1
  • 6