Last active
February 1, 2018 05:54
-
-
Save lucien144/d7b2901df5cd98f94815ca37f8a9f91e to your computer and use it in GitHub Desktop.
Basic MongoDB commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create new database & new collection | |
use new_db | |
db.new_db.save({test: 'test'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create root user | |
use admin | |
db.createUser( | |
{ | |
user: "root", | |
pwd: "*******", | |
roles: ["root"] | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates new user with access to one database only | |
use new_db | |
db.createUser( | |
{ | |
user: "new_db", | |
pwd: "*************", | |
roles: ["readWrite"] | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongo -u root -p --authenticationDatabase admin | |
> use admin | |
> db.createUser( | |
> { | |
> user: "backup", | |
> pwd: "************", | |
> roles: ["backup"] | |
> } | |
> ); | |
mongodump -u backup -p *********** --out /var/backups/mongobackups/`date +"%m-%d-%y"` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment