* docs: updated installation env vars and runtime values references * docs: fix content * docs: update content * Update table of contents, and refactored docs. * Fixed capitalization. * batch update to fix readability * refactored declarative env var * Updated translation. * Updated based on suggestions. * Updated based on suggestions. --------- Co-authored-by: yajing wang <413741312@qq.com>
76 lines
2.5 KiB
Markdown
76 lines
2.5 KiB
Markdown
---
|
|
outline: [2, 3]
|
|
description: Learn how to integrate your app with MongoDB service in Olares.
|
|
---
|
|
# Integrate with MongoDB
|
|
|
|
Use Olares MongoDB middleware by declaring it in `OlaresManifest.yaml`, then mapping the injected values to your container environment variables.
|
|
|
|
## Install MongoDB service
|
|
|
|
Install the MongoDB service from Market.
|
|
|
|
1. Open Market from Launchpad and search for "MongoDB".
|
|
2. Click **Get**, then **Install**, and wait for the installation to complete.
|
|
|
|
Once installed, the service and its connection details will appear in the Middleware list in Control Hub.
|
|
|
|
## Configure `OlaresManifest.yaml`
|
|
|
|
In `OlaresManifest.yaml`, add the required middleware configuration.
|
|
|
|
- Use the `username` field to specify the MongoDB database user.
|
|
- Use the `databases` field to request one or more databases.
|
|
- (Optional) Use the `script` field under each database to specify initialization scripts that are executed after the database is created.
|
|
|
|
**Example**
|
|
```yaml
|
|
middleware:
|
|
mongodb:
|
|
username: chromium
|
|
databases:
|
|
- name: chromium
|
|
script:
|
|
- 'db.getSiblingDB("$databasename").myCollection.insertOne({ x: 111 });'
|
|
# Please make sure each line is a complete query.
|
|
```
|
|
|
|
## Map to environment variables
|
|
|
|
In your deployment YAML, map the injected `.Values.mongodb.*` fields to the container environment variables your app requires.
|
|
|
|
**Example**
|
|
```yaml
|
|
containers:
|
|
- name: my-app
|
|
# For MongoDB, the corresponding values are as follows
|
|
env:
|
|
- name: MONGODB_HOST
|
|
value: "{{ .Values.mongodb.host }}"
|
|
|
|
- name: MONGODB_PORT
|
|
value: "{{ .Values.mongodb.port }}"
|
|
|
|
- name: MONGODB_USER
|
|
value: "{{ .Values.mongodb.username }}"
|
|
|
|
- name: MONGODB_PASSWORD
|
|
value: "{{ .Values.mongodb.password }}"
|
|
|
|
# Database name
|
|
# The database name configured in OlaresManifest (e.g., app_db)
|
|
- name: MONGODB_DATABASE
|
|
value: "{{ .Values.mongodb.databases.app_db }}"
|
|
```
|
|
|
|
## MongoDB values reference
|
|
|
|
MongoDB values are predefined runtime values injected into `values.yaml` during deployment. They are system-managed and not user-editable.
|
|
|
|
| Value | Type | Description |
|
|
| --- | --- | --- |
|
|
| `.Values.mongodb.host` | String | MongoDB host. |
|
|
| `.Values.mongodb.port` | Number | MongoDB port. |
|
|
| `.Values.mongodb.username` | String | MongoDB username. |
|
|
| `.Values.mongodb.password` | String | MongoDB password. |
|
|
| `.Values.mongodb.databases` | Map\<String,String> | Requested databases, keyed by database name. For example, a request for `app_db` is available at `.Values.mongodb.databases.app_db`. | |