# Database

## Step-by-step

### 1. Access the repository on GitHub via the link

{% hint style="info" %}
<https://github.com/guiaedutec/geos-database>
{% endhint %}

### 2. Clone the repository to your server

```bash
$ git clone https://github.com/guiaedutec/geos-database.git
```

### 3. Access the created folder

```bash
$ cd geos-database
```

### 4. By default the exposed port for the database is **30998**.

If you need to change, the settings are stored in the file.

It is necessary to create a password for the database root user *(line 10)*

{% hint style="info" %}
*The password must be alphanumeric with at least 6 characters*
{% endhint %}

{% code title="./docker-compose.yml" %}

```yaml
version: "3.4"
services:
  mongo:
    image: mongo:4.2.12
    container_name: geos-database
    environment:
      - PUID=1000
      - PGID=1000
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=<password-root-database>
      - MONGO_INITDB_DATABASE=guia_edutec
    ports:
      - "30998:27017"
    restart: unless-stopped
    networks:
      - geos-network
    volumes:
      - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
  mongo-seed:
    build: ./mongo-seed
    networks:
      - geos-network
    depends_on:
      - mongo
    links:
      - mongo
networks:
  geos-network:
```

{% endcode %}

### 5. Default User Setting: **geos**

Now create another password for the default user. The password must be the same in the two files below:

{% hint style="info" %}
*The password must be alphanumeric with at least 6 characters*
{% endhint %}

{% tabs %}
{% tab title="Mongo Init" %}
{% code title="./mongo-init.js" %}

```javascript
db.createUser(
  {
      user: "geos",
      pwd: "<password-default>",
      roles: [
          {
              role: "readWrite",
              db: "guia_edutec"
          }
      ]
  }
);
```

{% endcode %}
{% endtab %}

{% tab title="Dockerfile" %}
{% code title="./mongo-seed/Dockerfile" %}

```
FROM mongo:4.2.12

COPY database/guia_edutec /guia_edutec
CMD  mongorestore --host=mongo --db=guia_edutec -u geos -p <password-default> --authenticationMechanism SCRAM-SHA-256 /guia_edutec --gzip --drop
```

{% endcode %}
{% endtab %}
{% endtabs %}

### 6. To start the database, **only the first time**, run the **docker** command, as shown below:

```bash
~/geos-database$ docker-compose up -d --build
```

### 7. After the database is initialized, if the container is not running, just run the **docker** command, as shown below:

```bash
~/geos-database$ docker-compose up -d mongo
```

{% hint style="danger" %}
**Attention!**

*If the application is deployed on the Windows operating system, it is necessary to use the* [*Windows Subsystem for Linux (WSL) 2*](https://docs.docker.com/docker-for-windows/wsl/)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devops.guiaedutec.com.br/database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
