Showing posts with label MongoDB. Show all posts

Tuesday, September 15, 2020

Allow remotely mongodb connection

  No comments
September 15, 2020

In this tutorial, I will teach you how to make a remote Mongodb connection on the Google Cloud Platform


1. Edit mongod.conf

vim /etc/mongod.conf

2. Change bindIP to 0.0.0.0 or add your mongo host IP

         bindIp: 0.0.0.0

or

bindIp: 127.0.0.1 <your mongodb host IP> 

3. Save and restart mongod

sudo systemctl restart mongod

sudo systemctl status mongod

4. After that, go to your Google Cloud Platform console.  and type

gcloud compute firewall-rules create allow-mongodb --allow tcp:27017

and the result is 

Creating firewall...⠹Created [https://www.googleapis.com/compute/v1/projects/trastid/global/firewalls/allow-mongodb].Creating firewall...done.NAME NETWORK DIRECTION PRIORITY ALLOW DENY DISABLED

allow-mongodb default INGRESS 1000 tcp:27017 False

Now you can remote you mongodb with mongodb client, try this command on your terminal to test connection.

mongo admin -u <mongo user> -p <mongo password> --host <your mongo host IP> --port 27017  

 change the tag <text> with your configuration

Read More

How to Enable Access Control in MongoDB

  No comments
September 15, 2020

 After you install mongodb and get the warning to enable access control. You can follow this step

Enable Access Control

1. Start MongoDB without access control. (No need, if service already running)

mongod --port 27017

2. Connect to the instance

mongo --port 27017

3. Create the user administrator

> use admin

switched to db admin

> db.createUser(

...   {

...     user: "superman",

...     pwd: "rahasia",

...     roles: [ { role: "root", db: "admin" } ]

...   })

4. Re-start the MongoDB instance with access control

sudo service mongod restart   

5. Add the security.authorization setting to the config file

sudo vi /etc/mongod.conf 

systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
security:
authorization: enabled

6. Restart mongodb 

sudo service mongod restart

7. Connect to database

mongo --port 27017 -u "superman" -p "rahasia" --authenticationDatabase "admin"

now the warning has disappeared

Read More

Install MongoDB ubuntu

  No comments
September 15, 2020

How to Install MongoDB Community Edition, you can follow the steps in Mongodb documentation.

type this command on your terminal.

1. Import public key

wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

2. create list of mongodb

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

3. Reload local package

sudo apt-get update

4. Install the mongodb packages

sudo apt-get install -y mongodb-org

5. Start MongoDB

sudo systemctl start mongod

6. Verify the status

sudo systemctl status mongod

7. Using mongodb

mongo


if you got warning "Enable Access Control" when running mongodb. You can follow this step to fix it.

How to Enable Access Control MongoDB

Read More