Cara Install MongoDB 5 di Ubuntu 20.04
MongoDB adalah perangkat lunak database document-oriented dengan format JSON. MongoDB termasuk ke dalam kategori NoSQL database.
MongoDB tersedia dalam tiga edisi:
- MongoDB Community Server: gratis, bisa diinstall di Windows, Linux, dan macOS.
- MongoDB Enterprise Server: berbayar atau subscription.
- MongoDB Atlas: berjalan di atas cloud service AWS, Azure, dan Google Cloud Platform.
Install MongoDB
Import MongoDB public GPG key.
1 | wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add - |
Membuat file repository MongoDB.
1 | echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list |
Update dan install MongoDB.
1 2 | apt update apt install mongodb-org -y |
Jalankan mongod service.
1 2 3 | systemctl enable mongod systemctl start mongod systemctl status mongod |
Membuat User Admin
Login ke mongo shell.
1 | mongosh |
Gunakan database admin.
1 | use admin |
Membuat user admin dengan username mongoadmin dan password rahasia.
1 2 3 4 5 6 7 | db.createUser ( { user: "mongoadmin", pwd: "rahasia", roles: [{role: "userAdminAnyDatabase", db:"admin"}, "readWriteAnyDatabase"] } ) |
Keluar dari mongosh, ketik exit atau CTRL+D.
Mengaktifkan Authentication
Buka file /etc/mongod.conf.
1 | nano /etc/mongod.conf |
Cari baris security, hapus tanda # dan tambahkan opsi authorization.
1 2 | security: authorization: enabled |
Restart mongod service.
1 | systemctl restart mongod |
Login dengan User dan Password
Login dengan menggunakan username mongoadmin dan password rahasia.
1 | mongosh -u mongoadmin -p --authenticationDatabase admin |
Selamat mencoba 🙂
mohon maaf Pak Musa izin bertanya, saya install mongodb 5 di ubuntu 20.04 tapi failed to start boleh mintan solusinya?
artatripamuda@artatripamuda:~$ sudo systemctl status mongod
● mongod.service – MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset>
Active: failed (Result: core-dump) since Wed 2021-09-22 11:00:41 WIB; 38s >
Docs: https://docs.mongodb.org/manual
Process: 33349 ExecStart=/usr/bin/mongod –config /etc/mongod.conf (code=du>
Main PID: 33349 (code=dumped, signal=ILL)
Sep 22 11:00:40 artatripamuda systemd[1]: Started MongoDB Database Server.
Sep 22 11:00:41 artatripamuda systemd[1]: mongod.service: Main process exited, >
Sep 22 11:00:41 artatripamuda systemd[1]: mongod.service: Failed with result ‘c>
cek file konfigurasi, mungkin ada kesalahan ketik
You are able follow this tutorial : https://www.youtube.com/watch?v=HhfnuGcB3wc