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!
¹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.
-
Install the Strapi mongoose connector
yarn add strapi-connector-mongoose
-
Replace the PostgreSQL configuration in your
.platform/services.yaml
file with the following:.platform/services.yamlmongodb: type: mongodb:3.6 disk: 512
Note that the minimum disk size for MongoDB is 512MB.
-
In your
.platform.app.yaml
file, replace the relationship name to match the MongoDB database you added:.platform.app.yamlrelationships: mongodatabase: service: "mongodb" endpoint: "mongodb"
-
In the
config
folder, locate thedatabase.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.