Ubuntu16.04 Plain state on the server borrowed from linode
The latest version of mongodb is not available with apt-get. (By default) Introduced by making it available with apt-get
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install mongodb-org
If you execute it as it is, an error will occur. Because there is no directory.
sudo mkdir /data
sudo mkdir /data/db
sudo chmod -R 770 /data/db
sudo chown test /data/db
mongoDB does not start automatically For Ubuntu 16.04 LTS, you can execute it with the following command.
echo -e "[Unit]\nDescription=MongoDB Database Service\nWants=network.target\nAfter=network.target\n\n[Service]\nExecStart=/usr/bin/mongod --config /etc/mongod.conf\nExecReload=/bin/kill -HUP $MAINPID\nRestart=always\nUser=mongodb\nGroup=mongodb\nStandardOutput=syslog\nStandardError=syslog\n\n[Install]\nWantedBy=multi-user.target" | sudo tee /lib/systemd/system/mongod.service
sudo systemctl start mongod
sudo systemctl enable mongod
Check the version for the time being.
mongo -v
mongod -v
You need to start the server and shell to start mongodb. Start the mongoDB server in the background.
mongod &
First, start the mongodb shell
mongo
Execute with shell running
//Select database
use test
//Insert data into collection
db.test.insert({"test":"data"})
//Display the inserted result
db.test.find()
Recommended Posts