Install MongoDB on Ubuntu 18.04 LTS – Google Cloud. MongoDB is an open-source NoSQL database written in C++. This guide gives you a great understanding on installing and setting up MongoDB on Google Cloud Platform.
Prerequisites
Up and running Compute Engine, see the Setting up Compute Engine Instance.
Install MongoDB
Once you have your Compute Engine Instance up and running you can start installing MongoDB by updating the packages list.
sudo apt update
sudo apt install -y mongodb
Now MongoDB server will get installed. Once the installation is completed the database server will start automatically.
Verify Installation and Connection
Now you can verify the status of your installation by the following command.
sudo systemctl status mongodb
This command gives an output similar to this.
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2018-12-31 04:55:05 UTC; 59s ago
Docs: man:mongod(1)
Main PID: 2685 (mongod)
Tasks: 23 (limit: 667)
CGroup: /system.slice/mongodb.service
└─2685 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf
Dec 31 04:55:05 mongo systemd[1]: Started An object/document-oriented database.
You will see the status as Active: active (running)
Now the database server is running and you can check the connection to MongoDB.
mongo --eval 'db.runCommand({ connectionStatus: 1, showPrivileges: true})'
You will see the output with "ok" : 1
. This means your connection is successful.
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
{
"authInfo" : {
"authenticatedUsers" : [ ],
"authenticatedUserRoles" : [ ],
"authenticatedUserPrivileges" : [ ]
},
"ok" : 1
}
MongoDB Service Commands
You can start
, stop
, enable
, disable
, restart
using the following commands.
Start MongoDB
sudo systemctl start mongodb
Stop MongoDB
sudo systemctl stop mongodb
Enable MongoDB
sudo systemctl enable mongodb
Disable MongoDB
sudo systemctl disable mongodb
Restart MongoDB
sudo systemctl restart mongodb
Now MongoDB database is installed on Ubuntu 18.04 on Google Cloud Platform successfully.