Pada kesempatan kali ini saya akan membahas cara Install mongodb pada Rocky Linux
- tambah repo
cat > /etc/yum.repos.d/mongodb.repo << 'EOL'
[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
EOL
- install mongodb
dnf install mongodb-org
- cek version
mongod --version
- start service
systemctl start mongod
systemctl status mongod
systemctl enable mongod
- cek log
tail /var/log/mongodb/mongod.log
- login ke mongodb
mongo
- cek list db
db
use database-name
show collections
- create DB
use testdatabase
db.userdetails.insertOne(
{ "F_Name" : "fname",
"L_NAME" : "lname",
"ID_NO" : "12345",
"AGE" : "19",
"TEL" : "654321"
}
)
{
"acknowledged" : true,
"insertedId" : ObjectId("5da6036c387fad741503e4a1")
}
- create user
db.createUser(
{
user: 'testuser',
pwd: 'P@ssWord',
roles: [ { role: 'readWrite', db: 'testdatabase' } ]
}
);
- lihat list db
show collections
db.NAME-OF-COLLECTION.find().pretty()
(Visited 53 times, 1 visits today)