# MongoDB - Roboshop Project

we start mongoDB now

Instance Code

```plaintext
{
  "MaxCount": 1,
  "MinCount": 1,
  "ImageId": "ami-0089b8e98cd95257d",
  "InstanceType": "t3.micro",
  "EbsOptimized": true,
  "NetworkInterfaces": [
    {
      "DeviceIndex": 0,
      "AssociatePublicIpAddress": true,
      "SubnetId": "subnet-086a045ade7eae99f",
      "Groups": [
        "sg-0c2e3fdd288a74d3a"
      ]
    }
  ],
  "TagSpecifications": [
    {
      "ResourceType": "instance",
      "Tags": [
        {
          "Key": "Name",
          "Value": "frontend"
        }
      ]
    },
    {
      "ResourceType": "spot-instances-request",
      "Tags": [
        {
          "Key": "Name",
          "Value": "frontend"
        }
      ]
    }
  ],
  "InstanceMarketOptions": {
    "MarketType": "spot",
    "SpotOptions": {
      "InstanceInterruptionBehavior": "stop",
      "SpotInstanceType": "persistent"
    }
  },
  "PrivateDnsNameOptions": {
    "HostnameType": "ip-name",
    "EnableResourceNameDnsARecord": true,
    "EnableResourceNameDnsAAAARecord": false
  }
}
```

## **MongoDB Installation and Configuration**

In RoboShop, the database management system MongoDB has been chosen to store and manage data. Here's how to install and configure it:

### **Step 1: Set up MongoDB repository**

Before installing MongoDB, we need to set up its repository. Create a new file called `mongo.repo` in the directory `/etc/yum.repos.d/` using the following command:

```plaintext
sudo vim /etc/yum.repos.d/mongo.repo
```

Then, add the following lines to the file:

```plaintext
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=0
enabled=1
```

### **Step 2: Install MongoDB**

Once the repository is set up, we can install MongoDB using the following command:

```plaintext
sudo yum install mongodb-org -y
```

### **Step 3: Start and enable MongoDB service**

Start and enable the MongoDB service using the following commands:

```plaintext
sudo systemctl enable mongod
sudo systemctl start mongod
```

### **Step 4: Update MongoDB configuration**

By default, MongoDB only listens to connections from the local machine ([localhost](http://localhost)). In order to allow connections from other servers, we need to update the MongoDB configuration file.

Open the configuration file `/etc/mongod.conf` in your text editor:

```plaintext
sudo vim /etc/mongod.conf
```

Find the line that starts with `bindIp` and change the value from `127.0.0.1` to `0.0.0.0`.

```plaintext
# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.
```

### **Step 5: Restart MongoDB service**

After updating the MongoDB configuration file, restart the MongoDB service to apply the changes:

```plaintext
sudo systemctl restart mongod
```

That's it! MongoDB is now installed and configured to accept connections from other servers.
