v1

Databases And Persistence /

Deploy MongoDB on Northflank

This guide explains how to quickly and easily deploy and use MongoDB on Northflank.

Available versionsDescriptionBackupsTLS
5.0.11, 4.4.15, 4.2.21MongoDB is a document-oriented database program that uses JSON-like documents with schema.Native or diskYes

Deploy MongoDB

  1. Choose addon from the create new menu in the top right corner of the dashboard

  2. Select MongoDB and enter a name

  3. Choose a version or leave as default (most recent version)

  4. Choose whether to deploy with TLS. This can be changed later.

  5. Choose whether to make the database publicly accessible. This will give your database a URL and make it available online. TLS must be enabled to select this.

  6. If you have secret groups in your project, choose ones to link to the addon so that the database can be used in services and jobs that inherit variables from the secret group. To link the database to a secret group:

    • Show secret groups and configure the secret groups you wish to use
    • Select suggested secrets from the database to link, or select all
    • Set any required aliases for specific secrets to make them accessible by that name within your application
  7. Select the required resources for your database. You can scale the database after creation, but available storage and replicas cannot be decreased once increased.

  8. Create addon and MongoDB will begin provisioning, this may take a few minutes.

Connect to MongoDB

You can manually copy the connection secrets for your MongoDB database from the connection details page into environment variables or build arguments of your workloads on Northflank.

However, it is much easier to link your database's connection details to a new or existing secret group.

The necessary secrets to connect your workload will vary depending on the application in your workload.

Some clients may use the MongoDB connection string , while some clients may not support the connection string URI format.

The connection string takes the format mongodb://[username:password@][host][:port][/database][...options], options include specifying the replica set, authentication source, and TLS requirement. The mongoSrv connection string will be automatically configured for your database.

You can supply connections details and secrets such as host, database, username, password, and port to your workload if your application is configured to use these instead of a connection string.

Available ports

PortProtocolURL prefix
27017MongoDBmongodb://

Automatically inherit database connection details into your workload

  1. Create a new secret group of runtime variables to connect in the running workload
  2. Show addons and configure your addon with either the mongoSrv connection string, or select connection details and secrets
  3. Set the aliases required in your workload to access the secrets
  4. Enable apply secrets to specific services/jobs and select the workloads you want to access the database
  5. Create secret group
  6. Go to one of the workloads that inherits from the group and check the environment page, you should see the inherited variables from the secret group

The connection string or secrets will now be available in your workload under the configured aliases, and your application will be able to connect to the database using them.

Access MongoDB

Access locally

To forward your MongoDB database for local access using the Northflank CLI, copy and execute the forward addon command from the local access section of the overview.

You can then use the connection details to access your MongoDB deployment in your local development environment.

Access externally

To access your MongoDB database externally, ensure deploy with TLS and publicly accessible are enabled on the settings page under networking. The connection strings will be updated with the new configuration.

Scale MongoDB

You can scale your MongoDB database on the resources page. You can increase the CPU and memory, storage, and replicas available to your database.

Compute plan

You can change the compute plan to improve performance for more intensive workloads.

Storage

You can increase storage, but not decrease it. You should increase storage if your database uses over 50% of the available storage.

Replica behaviour

You can increase the number of available replicas, but you cannot decrease them. If a primary node becomes unavailable one of the replica nodes will be promoted to primary, supporting read/write operations.

MongoDB specifications

Maximum connections

MongoDB allows up to 65,536 connections by default. However, due to an issue with MongoDB this default limit is ignored and the maximum number of connections depends on the maximum number of open files limit set on the host system.

Your addon will be able to handle more concurrent connections by increasing the available CPU and memory. You can do this by selecting the compute plan on the addon's resources page.

© 2022 Northflank Ltd. All rights reserved.