[go: up one dir, main page]

Skip to content

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.

ValueTypeDescription
.Values.mongodb.hostStringMongoDB host.
.Values.mongodb.portNumberMongoDB port.
.Values.mongodb.usernameStringMongoDB username.
.Values.mongodb.passwordStringMongoDB password.
.Values.mongodb.databasesMap<String,String>Requested databases, keyed by database name. For example, a request for app_db is available at .Values.mongodb.databases.app_db.