Databases

Overview

io.Manager supports connecting to MongoDB databases. The following sections outline the steps and requirements for configuring io.Manager to work with MongoDB databases.

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 settings via the configuration object for initializing the io.Manager Server.

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

Configuration Object

To configure io.Manager to connect to a MongoDB database, you must provide the necessary settings 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.

Example

For a complete example of connecting io.Manager to a MongoDB database, see the MongoDB Database example on GitHub.