Learning MongoDB
(4 tomatoes: install + crud)
Note, --host 127.0.0.1:27017
is the default for most cmd, but the bound IP may be NOT 127.0.0.1 or localhost, it can be another NIC with LAN-only instead.
Install #
to install #
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5 && \
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list && \
sudo apt-get update && \
sudo apt-get install -y mongodb-org
to prevent update #
dpkg -l | grep mongo
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
run the server #
# start service:
sudo service mongod start
# check:
cat /var/log/mongodb/mongod.log
connect from the client to the server and open mongo-shell (bash) #
# start shell:
mongo
# or:
mongo --host 127.0.0.1:27017
# or:
mongo database_name
authenticate a user #
after getting into a mongo-shell:
...