Databases

Overview

The default deployment of io.Manager comes with a configured MongoDB database. The following sections outline the steps and requirements for configuring io.Manager to work with your own MongoDB database.

Connecting to MongoDB Databases

To configure io.Manager to connect to a MongoDB database, you must either set the necessary environment variables, or provide the required configuration at runtime.

Depending on the deployment approach you have chosen, you have the following options:

The following sections provide examples of both options.

Environment Variables

To configure io.Manager to connect to a MongoDB database, you must register all of the following environment variables with the proper values. The API_STORE_TYPE environment variable must be set to mongo. All other variables must be set with values according to your specific environment:

Environment Variable Description
API_STORE_TYPE Type of the database. Must be set to mongo.
API_STORE_MONGO MongoDB connection URL.

Example settings:

API_STORE_TYPE=mongo
API_STORE_MONGO=mongodb://localhost:27017/my_db

Runtime Configuration

To configure io.Manager to connect to a MongoDB database, you must provide the necessary settings at runtime when initializing the io.Manager Server. Use the store property of the optional Config object and provide a MongoStoreConfig object as its value.

The following example demonstrates configuring the connection to a MongoDB database when initializing the io.Manager Server:

import { start } from "@interopio/manager";

// Configuration for the io.Manager Server.
const config = {
    name: "my-server",
    port: 4242,
    token: {
        secret: "my-secret"
    },
    // Configuration for connecting to a MongoDB database.
    store: {
        type: "mongo",
        connection: "mongodb://localhost:27017/my_db"
    }
};

// Initializing the io.Manager Server.
const server = await start(config);

The store object has the following properties:

Property Type Description
connection string Required. MongoDB connection URL.
type "mongo" Required. Type of the data store. Must be set to "mongo" when using a MongoDB database.