# Установка MongoDB

{% hint style="info" %}
Данный пункт необходим только при установке в режиме **Source** по умолчанию мы используем систему Docker в ней не нужно устанавливать отдельно MongoDB
{% endhint %}

{% tabs %}
{% tab title="Debian 11" %}
{% hint style="warning" %}
**Внимание!** Инструкция только для **Debian 11**, если у вас другая версия системы, используйте [официальную документацию](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/)
{% endhint %}

Добавление ключей:

```bash
sudo apt-get install -y gnupg
```

```bash
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
   --dearmor
```

```bash
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
```

```bash
sudo apt-get update
```

Установка:

```bash
apt-get install -y mongodb-org
```

Запуск и добавление в автозапуск:

```bash
sudo systemctl start mongod
```

```bash
sudo systemctl daemon-reload
```

```bash
sudo systemctl enable mongod
```

Создание базы данных и пароля:

```bash
mongosh
```

продолжайте по инструкции ниже
{% endtab %}

{% tab title="Debian 10" %}
{% hint style="warning" %}
**Внимание!** Инструкция только для **Debian 10**, если у вас другая версия системы, используйте [официальную документацию](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/)
{% endhint %}

Добавление ключей:

```bash
sudo apt-get install -y gnupg
```

```bash
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
   sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
   --dearmor
```

```bash
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] http://repo.mongodb.org/apt/debian buster/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
```

```bash
sudo apt-get update
```

Установка:

```bash
sudo apt-get install -y mongodb-org
```

Запуск и добавление в автозапуск:

```bash
sudo systemctl start mongod
```

```bash
sudo systemctl daemon-reload
```

```bash
sudo systemctl enable mongod
```

Создание базы данных и пароля:

```bash
mongosh
```

продолжайте по инструкции ниже...
{% endtab %}

{% tab title="Другая ОС" %}
{% hint style="info" %}
Воспользуйтесь официальной документацией от MongoDB \
[Официальные документы](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/)
{% endhint %}
{% endtab %}
{% endtabs %}

{% hint style="danger" %}
**Внимание!** В коде ниже есть переменные их нужно придумать свои (`ADMIN_NAME, ADMIN_PASSWORD, DB_NAME, USER_NAME, YOUR_PASSWORD, DB_NAME`) эти данные не следует никому разглашать, это доступы к вашим базам данных разгласив их или использовав команду без изменений, вы рискуете быть взломанными!
{% endhint %}

{% code lineNumbers="true" %}

```javascript
use admin;
db.createUser({
  user: "ADMIN_NAME",
  pwd: "ADMIN_PASSWORD",
  roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
});
use DB_NAME;
db.createUser({
  user: "USER_NAME",
  pwd: "YOUR_PASSWORD",
  roles: [ { role: "readWrite", db: "DB_NAME" } ]
});
exit
```

{% endcode %}

Активация авторизации для MongoDB

```bash
nano /etc/mongod.conf
```

{% code title="/etc/mongod.conf" lineNumbers="true" %}

```yaml
security:
      authorization: "enabled"   
```

{% endcode %}


---

# 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://manual.boxexchanger.net/dlya-razrabotchikov/ustanovka-proekta/ustanovka-po/ustanovka-mongodb.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.
