When I create backup of all databases in MongoDB (version 3):
mongodump --username bacUser --password 12345
It\'s OK. But when I try to cre
If you still get same error with --authenticationDatabase admin , than probably your username and password are incorrect. Try adding a user db.createUser() , with appropriate role ( i gave write permission as well)
than run below command : (ignore -h if you are running on local)
mongodump -h <ip>:<port_number> -d db_name -u newUser -p newPassword -o /home/mongodump/
Hope this helps...
Use signle Quotation around password. if you are using any special character in your password. That will solve your issue. Use following command.
mongodump -d database_name -u userName -p 'password' --out directory_name
mongodump --authenticationDatabase admin -uroot -pyourpassword
here root is username and yourpassword is your password.
This command will backup/dump all database back-up in current directory.
userAdminAnyDatabase is not enough to do mongodump on all the dbs that's why you are getting this error. You will need a super user that has:
userAdminAnyDatabase
readWriteAnyDatabase
clusterAdmin
privileges to run mongodump on all dbs.
OR you just need 'backup' privilege
db.grantRolesToUser('username', [{
role: 'backup',
db: 'name of ur authentication db'
}])
for dump and restore
mongodump --db nameDatabase --username userName --password password --authenticationDatabase admin --out mongodb\
mongorestore --db nameDatabase --username userName --password password --authenticationDatabase admin <path backup> --drop
In my case, mongodump
was not correctly processing the password. The solution was to escape the password literal.
This did not work:
mongodump -p my$password -o <output directory>
This did work:
mongodump -p 'my$password' -o <output directory>