User Documentation

Configure MongoDB for Strapi on

Sign up for Upsun

Get your free trial by clicking the link below.

Get your Upsun free trial

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, 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:

        type: mongodb:3.6
        disk: 512

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

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

        mongodatabase: "mongodb: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()) {
      // database configuration.
      const credentials = config.credentials(dbRelationshipMongo);
        `Using configuration with relationship ${dbRelationshipMongo}.`
      settings = {
        client: "mongo",
        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.
          "Using default configuration during build hook until relationships are available."
      } else {
        // Strapi default local configuration.
          "Not in a Environment. Using default local sqlite configuration."
    module.exports = {
      defaultConnection: "default",
      connections: {
        default: {
          connector: "mongoose",
          settings: settings,
          options: options,

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

Is this page helpful?