setp 1. Import the public key used by the package management system.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
step 2. Create a list file for MongoDB
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
step 3. Reload local package database
sudo apt-get update
step 4. Install the latest stable version of MongoDB
sudo apt-get install -y mongodb-org
start/stop mongod service
sudo service mongod stop #停止服务
sudo service mongod start #启动服务
sudo service mongod restart #重新启动服务
sudo service mongod status #查看状态
允许开机自启动
sudo systemctl enable mongod
删除mongodb
#停止mongodb服务
sudo service mongod stop
#删除包
sudo apt-get purge mongodb-org*
#删除数据文件及日志文件
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb