Last active
May 15, 2019 02:09
-
-
Save alexishida/10e1ee89065c998af851d56985e4a04b to your computer and use it in GitHub Desktop.
Mongodb Comands
This file contains hidden or 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
| # References | |
| https://www.digitalocean.com/community/tutorials/how-to-securely-configure-a-production-mongodb-server | |
| docker run -d \ | |
| --name=mongodb \ | |
| --restart=always \ | |
| -p 27017:27017 \ | |
| -v /etc/localtime:/etc/localtime:ro \ | |
| -v /mystorage/mongodb/db:/data/db \ | |
| -v /mystorage/mongodb/config/mongod.conf:/etc/mongo/mongod.conf \ | |
| -e MONGO_INITDB_ROOT_USERNAME=admin \ | |
| -e MONGO_INITDB_ROOT_PASSWORD=123456 \ | |
| mongo:3.4.20 --config /etc/mongo/mongod.conf | |
| mongo -u admin -p --authenticationDatabase admin | |
| use admin | |
| db.createUser( | |
| { | |
| user: "admin", | |
| pwd: "123456", | |
| roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] | |
| } | |
| ) | |
| use admin | |
| db.createUser({ user: 'admin', pwd: '123456', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] }); | |
| db.auth("admin", "senha") | |
| use app_development | |
| db.createUser({ user: "user_dev", pwd: "senha_dev", roles: [{ role: "dbOwner", db: "app_development" }] }) | |
| db.auth("user_dev", "senha_dev") | |
| show collections | |
| # mongod.conf | |
| # for documentation of all options, see: | |
| # http://docs.mongodb.org/manual/reference/configuration-options/ | |
| # network interfaces | |
| net: | |
| port: 27017 | |
| bindIp: 0.0.0.0 | |
| #security: | |
| security: | |
| authorization: "enabled" | |
| # Dump do banco | |
| # https://docs.mongodb.com/manual/tutorial/backup-and-restore-tools/ | |
| $ docker exec some-mongo sh -c 'exec mongodump -d <database_name> --archive' > /some/path/on/your/host/all-collections.archive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment