[MongoDB] How to install MongoDB on Linux

Hi guys! I’m going to explain how to install mongoDB on Ubuntu Linux.
ENVIRONMENT
- Ubtuntu 18.04 LTS
- MongoDB 4.2.3
Installing MongoDB
First, you have to update the packege list to have the most recent version of the repository:
$ sudo apt update
$ sudo apt update
$ sudo apt install -y mongodb
This command installs several packages containing the latest stable version of MongoDB, along with helpful management tools for the MongoDB server. The database server is automatically started after installation.
Next, let’s verify that the server is running and works correctly.
Checking the Service and Database
The installation process started MongoDB automatically, but let’s verify that the service is started and that the database is working. First, you can check the Service and Database:
$ sudo systemctl start mongod
$ sudo systemctl status mongod
or
$ sudo mongo service status
You’ll see this output:
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-05-26 07:48:04 UTC; 2min 17s ago
Docs: man:mongod(1)
Main PID: 2312 (mongod)
Tasks: 23 (limit: 1153)
CGroup: /system.slice/mongodb.service
└─2312 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf
According to systemd, the MongoDB server is up and running.
Now you can connect mongo with
$ mongo
below another commands:
> show dbs
> use databaseName
> show collection
> db.collection.find()
> db.help()
Creating Database
> use name_db
> db.users.save ( { username: "Saruman" } )
Db creates automatically.
Thank you!