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
The following steps worked for me on MongoDB 3.2:
mongo
use admin db.auth("admin", "yourpassword")
If this returns 1, the password is correct.
Then add the role "backup" to your admin (or make sure this role is already added). db.grantRolesToUser("admin", [{ role: "backup", db: "admin" }])
Finally, the mongodump command. It did not work for me when I tried to pass the password as an argument. Instead do this:
mongodump --username admin --authenticationDatabase admin --db yourmongodatabase
Then add your password when it promts for it.
This works for me...
If you are using mLab then it could be the version in your local mongo is not match with mLab. By default, Ubuntu will install mongo v2.x
and mLab is v3.x
. You could check with this command:
mongo --version
Install new mongo version:
sudo apt remove mongo-clients mongodb
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv D68FA50FEA312927
Create a list file for MongoDB.
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get install -y mongodb-org
Ref: https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/
Now you can dump your database with this command:
mongodump -h <host>:<port> -d <database-name> -u <user> -p <password> -o <output directory>
work with this:
--authenticationDatabase admin
mongodump and mongorestore commands need the name of database where mongodb user's credentials are stored. (thanks @Zubair Alam)
mongodump --collection coll_name --db DBname -u UName -p ***
--authenticationDatabase <admin/privileged> --host ip
--port portNo --out foldName
This should work.
mongodump -h SERVER_NAME:PORT -d DATABASE_NAME -u DATABASE_USER -p PASSWORD
Also this error can popup if username or password are wrong.
mongodump --host <host-ip> --port 27017 --db <database> --authenticationDatabase admin --username <username> --password <password> --out ./Documents/
After all the trail, I found above working command to dump from mongdb.