Please enable JavaScript.
Coggle requires JavaScript to display documents.
MongoDB (Install (Setup (Ubuntu with sudo privileges, Import Key for…
MongoDB
Setup
-
Import Key for official MongoDB repo
-
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Add MongoDB check:
-echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list`
Update the packages list:
Install
Download meta package including the daemon, config and init scripts:
sudo apt-get install mongodb-org
Start Mongo:
-
sudo systemctl start mongod
-
Verify that MongoD starts on Reboot:
-
sudo systemctl enable mongod
Secure
Background
Earlier version of MongoDB were vulnerable to automated exploits as by default no authentication was required
MongoDB Daemon used to listen on all interfaces by default therefore if no firewall would be ruined - now correct as daemon is bound to 127.0.0.1
Add Admin User
-
There is a database called admin
which designates what credentials for a particular user - there:
-
use admin
db.createUser(
{
user: "NAME",
pwd: "PASSWORD",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ],
}
)
Enable Authentication
-
In #security
section remove the hash infront of security section to enable
- Once completed restart daemon:
sudo systemctl restart mongod
- Check status
sudo systemctl status mongod
Verify Unauthenticated Users are Restricted
-
mongo
-
show dbs
Should get no access response
Verify Admin Users Access
-
mongo -u <USER> -p <PASS> admin
<ENTER PASSWORD>
Log into docker container
- Check mongo instance is running
docker ps
mongodump a mongo database in docker
-
docker run --rm --link mongodb:mongo -v /root:/backup mongo bash -c 'mongodump --out /backup --host mongo:27017'
- Where mongodb is the name of the mongo container
-
-v
is volume and it gives path for where everything will be dumped
-
Overview
Open Source, document-oriented database
-
-
-
-
Comparison to MySQL
In MySQL (relational) stores data in tables and uses Structured Query Language (SQL) for database access
In MySQL you pre-define database schema based on requirements and set up rules to govern relationships between fields
-
Atlas
MongoDB very own Saas
- Manages Security
- Scales Efficiently
- Increase Size on demand
- Consistent Uptime
-
Backups
mongorestore
To restore a database log into server and execute this command
sudo mongorestore --db articles --drop /var/backups/mongo-backup/09-04-18/articles -u <username> -p <password>
or
sudo mongorestore --db <database table> --drop /path/to./backup/binaries -u <username> -p <password>
Connection
Via SSH (More Secure)
-
Run this command:
ssh \
-L 4321:localhost:27017 \
(setup tunnel port 4321 will forward to mongo droplet port 27017)
-i ~/.ssh/my_secure_key \
(no password)
ssh_user@mongo_db_droplet_host_or_ip
-
-