Platform.sh is now Upsun. Click here to learn more
Upsun Fixed User Documentation

Configure MongoDB for Strapi on Upsun Fixed

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!¹ A monthly $19 perk!
Activate your 15-day trial
¹Terms and conditions apply

Strapi can also be configured to use MongoDB as its default database, although due to compatibility issues this database type is only available in Strapi v3 and not supported in Strapi v4. To use MongoDB with a Strapi v3 application on Upsun Fixed, follow these steps.

  1. Install the Strapi mongoose connector

    yarn add strapi-connector-mongoose
  2. Replace the PostgreSQL configuration in your .platform/services.yaml file with the following:

    .platform/services.yaml
    mongodb:
      type: mongodb:3.6
      disk: 512

Note that the minimum disk size for MongoDB is 512MB.

  1. In your .platform.app.yaml file, replace the relationship name to match the MongoDB database you added:

    .platform.app.yaml
    relationships:
      mongodatabase:
        service: "mongodb"
        endpoint: "mongodb"
  2. In the config folder, locate the database.js file, and replace its content with the following:

    const config = require("platformsh-config").config();
    let dbRelationshipMongo = "mongodatabase";
    
    // Strapi default sqlite settings.
    let settings = {
      client: "sqlite",
      filename: process.env.DATABASE_FILENAME || ".tmp/data.db",
    };
    
    let options = {
      useNullAsDefault: true,
    };
    
    if (config.isValidPlatform() && !config.inBuild()) {
      // Upsun Fixed database configuration.
      const credentials = config.credentials(dbRelationshipMongo);
    
      console.log(
        `Using Upsun Fixed configuration with relationship ${dbRelationshipMongo}.`
      );
    
      settings = {
        client: "mongo",
        host: credentials.host,
        port: credentials.port,
        database: credentials.path,
        username: credentials.username,
        password: credentials.password,
      };
    
      options = {
        ssl: false,
        authenticationDatabase: "main",
      };
    } else {
      if (config.isValidPlatform()) {
        // Build hook configuration message.
        console.log(
          "Using default configuration during Upsun Fixed build hook until relationships are available."
        );
      } else {
        // Strapi default local configuration.
        console.log(
          "Not in a Upsun Fixed Environment. Using default local sqlite configuration."
        );
      }
    }
    
    module.exports = {
      defaultConnection: "default",
      connections: {
        default: {
          connector: "mongoose",
          settings: settings,
          options: options,
        },
      },
    };

This configuration instructs Upsun Fixed to deploy your Strapi v3 app with a MongoDB database.