`mongorestore` 1 db to new name?

Working my way through the somewhat impenetrable documentation for mongodump and mongorestore (the docs could use one single Examples section with a comprehensive set of examples).

I did not manage to figure out how to dump 1 database from my server, so I dumped everything. Every form of the command I tried other than simply mongodump --uri='mongodb://admin:xxxxxxxx@example.com:27017' failed with:

Failed: can't create session: could not connect to server: connection() error occured during connection handshake: auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

Okay, so now I have a dump dir. Every form of mongorestore I try specifying a database and the target name to restore to fails with the same uninformative authentication error.

Can someone provide a mongorestore command line that will restore 1 database from the dump dir to a new name, e.g., restore mydb to mydb_bak ?

1 Like


If you already have dump folder, then you should be able to easily restore database with following command:

mongorestore --uri mongodb://admin:xxxxxxxx@example.com:27017 {{BSON_FILE_PATH}}

BSON_FILE_PATH is the path to the BSON file that was generated with mongodump. It will be inside the dump folder that was created.

You will see the name of the old database inside the dump folder, so you can change the name there directly, and mongorestore will restore the database with the new name.


Thanks @NeNaD , works for me:

$ mv dump/a/ dump/a_bak
$ mongorestore --uri='mongodb://admin:xxxxxxxx@example.com:27017' dump/a_bak/x.bson
$ mongorestore --uri='mongodb://admin:xxxxxxxx@example.com:27017' dump/a_bak/y.bson

… etc.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.