MongoDB

From Omnia
Jump to navigation Jump to search

MongoDB

MongoDB
https://www.mongodb.com/

Install MongoDB Community Edition

sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
  sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
  --dearmor
# Ubuntu 20:
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
# Ubuntu 22:
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Prevent unintended upgrades: (pin)

echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-mongosh hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections

ref:

Install MongoDB Community Edition on Ubuntu - MongoDB Manual v7.0
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/

Manage MonoDB Service

sudo systemctl start mongod
sudo systemctl daemon-reload
sudo systemctl status mongod
sudo systemctl enable mongod
sudo systemctl stop mongod
sudo systemctl restart mongod

Port 27017

port 27017

mongosh

mongosh

Uninstall MongoDB

Stop service:

sudo service mongod stop

Remove packages:

sudo apt-get purge "mongodb-org*"

Remove Data directories:

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

keywords