Mongodump db + users/roles

For the past few days i’ve been trying to backup my mongodb machine using mongodump.
The dump itself works just fine but when restored to a different machine to make sure the db was backed up fully I see that the users and all the settings were not moved.

My questions are as follows:
1.Is there a way to fully mongodump a db with all its users/roles/configs so after the restore I’ll basically have the same db to work on?
2.Where are the users and roles file/config located at?
3.Am I doing the backup restore correctly or is there a better way to do so?

Thanks !


  1. in the admin database.


  1. What commands are you using?
  1. thanks
    So if I export this using mongodump and restoring them I should have the same users and roles?
    Am I able to mongodump both collections at once? I tried using comma to separate between

using this command to backup
mongodump --db –username --password p --out /mongobackup/dump/mongobackup_$( date ‘+%Y-%m-%d_%H-%M-%S’ ) &> /mongobackup/backupout

and this to restore

mongorestore /mongobackup/dump/mongobackup_2021-08-01_15-09-57 &> /mongobackup/restoreout

If you are dumping a specific database you will want to use mongodump’s --dumpDbUsersAndRoles option and use the corresponding mongorestore --restoreDbUsersAndRoles option.

If you are mongodumping a whole instance the roles and uses are included.

1 Like

Thanks yeah I finally understood that and that my users/roles are stored in the Admin DB.
I wasn’t able to mongodump the full instance but when dumping and restoring my DB and the Admin DB it worked like a charm.Mongodump requires me to input a db name.

On more thing can I use mongodump with a different authentication method and not use username/password since it’s just saved in plain text.

Mongodump supports a few authentication methods via –authenticationMethod but these will require a password/passphrase(X509 a possible exception)

If your concern is having the password on the command line then you can put them in a config file using
–config option.

1 Like

I couldn’t find the --config option when trying mongodump is it possible its missing on version
Am I able to download just this ‘tool’ with a higher version but keep the DB itself with the old?

I will also be checking hte x509 authentication method


1 Like

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