In this lesson, I will show you how to install MongoDB on a Ubuntu Linux computer and how to run a MongoDB query.
Import Public Key:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
Creating List file for MongoDB:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Update Local Packages:
sudo apt-get update
Installing MongoDB Package:
sudo apt-get install -y mongodb-org
Checking MongoDB:
which mongo
which mongod
which mongos
which mongodump
which mongostat
which mongotop
which mongoimport
Starting MongoDB:
sudo systemctl start mongod
Checking MongoDB Status:
sudo systemctl status mongod
Stop MongoDB:
sudo systemctl stop mongod
Restart MongoDB:
sudo systemctl restart mongod
Running Mongo Shell:
mongo
MongoDB Configuration File:
vim /etc/mongod.conf
Stop MongoDB:
sudo systemctl stop mongod
Remove Package:
sudo apt-get purge mongodb-org*
Stop MongoDB Data Directory:
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb